<commit_before>/* jslint node: true */
/* jslint expr: true */
/*global describe, it, before, beforeEach, after, afterEach */
"use strict";

var chai = require('chai');
var assert = chai.assert;
var crypto = require('crypto');
var sha1 = function (value) {
  return crypto
    .createHash('sha1')
    .update(value)
    .digest('hex');
};

var ___ = 'probably wrong answer';

describe('JS Functions', function () {

  it('function expressions vs function declarations', function () {
    function isNimble() { return false; }
    var canFly = function () { return false; };
    this.isDeadly = function () { return false; };

    assert.isTrue(isNimble(), 'isNimble should be callable');
    assert.isTrue(canFly(), 'canFly as well');
    assert.isTrue(this.isDeadly(), 'and so isDeadly');
  });

  it('a function can be declared after being called, but not function expressions', function () {
    assert.isTrue(isNimble(), 'isNimble can be called before being declared');
    assert.isTrue(canFly(), 'but not canFly');
    assert.isTrue(this.isDeadly(), 'nor isDeadly');

    function isNimble() { return ___; }
    var canFly = function () { return true; };
    this.isDeadly = function () { return true; };
  });

  it('a function can be refered within its self using its name', function () {
    function yell(n){
      return n > 0 ? yell(n-1) + "a" : "hiy";
    }
    assert.equal(yell(4), ___, "Calling the function by itself comes naturally." );
  });

  it('naming a function', function () {
    var ninja = function myNinja(){
      assert.equal(___, myNinja, "This function is named two things - at once!" );
    };
    ninja();
    assert.equal(typeof ___, "undefined", "But myNinja isn't defined outside of the function." );
  });

  it('function can be used by their name as an object property', function () {
    var ninja = {
      yell: function(n){
        return n > 0 ? ninja.yell(n-1) + "a" : "hiy";
      }
    };
    assert( ninja.yell(5) == ___, "A single object isn't too bad, either." );
  });

  it('a function should always have a proper name', function () {
    var ninja = {
      yell: function ___(n){
        return n > 0 ? ninja.yell(n-1) + "a" : "hiy";
      }
    };

    var samurai = { yell: ninja.yell };
    var ninja = null;


    assert.doesNotThrow(function () {
      samurai.yell(4);
    }, Error, "Uh, this isn't good! Where'd ninja.yell go?");
  });

  it('a function is also an object, and can have properties', function () {
    var obj = {};
    var fn = function(){};
    obj.prop = "some value";<commit_msg>fix koans #1 on functions<commit_after>/* jslint node: true */
/* jslint expr: true */
/*global describe, it, before, beforeEach, after, afterEach */
"use strict";

var chai = require('chai');
var assert = chai.assert;
var crypto = require('crypto');
var sha1 = function (value) {
  return crypto
    .createHash('sha1')
    .update(value)
    .digest('hex');
};

var ___ = 'probably wrong answer';

describe('JS Functions', function () {

  it('function expressions vs function declarations', function () {
    function isNimble() { return ___; }
    var canFly = function () { return ___; };
    this.isDeadly = function () { return ___; };

    assert.isTrue(isNimble(), 'isNimble should be callable');
    assert.isTrue(canFly(), 'canFly as well');
    assert.isTrue(this.isDeadly(), 'and so isDeadly');
  });

  it('a function can be declared after being called, but not function expressions', function () {
    var canFly;

    assert.isTrue(isNimble(), 'isNimble can be called before being declared');
    assert.isTrue(canFly(), 'but not canFly');
    assert.isTrue(this.isDeadly(), 'nor isDeadly');

    function isNimble() { return ___; }
    canFly = function () { return true; }; // what can you do with this line to make the test pass ?
    this.isDeadly = function () { return true; }; // what can you do with this line to make the test pass ?
  });

  it('a function can be referred within its self using its name', function () {
    function yell(n) {
      return n > 0 ? ___(n-1) + "a" : "hiy";
    }
    assert.equal(yell(4), ___, "Calling the function by itself comes naturally." );
  });

  it('naming a function', function () {
    var ninja = function myNinja(){
      assert.equal(___, myNinja, "This function is named two things - at once!" );
    };
    ninja();
    assert.equal(typeof ___, "undefined", "But myNinja isn't defined outside of the function." );
  });

  it('function can be used by their name as an object property', function () {
    var ninja = {
      yell: function(n){
        return n > 0 ? ninja.___(n-1) + "a" : "hiy";
      }
    };
    assert.equal(ninja.yell(5), ___, "A single object isn't too bad, either.");
  });

  it('a function should always have a proper name', function () {
    var ninja = {
      yell: function ___(n){
        return n > 0 ? yell(n-1) + "a" : "hiy";
      }
    };

    var samurai = { yell: ninja.yell };
    var ninja = null;

    assert.doesNotThrow(function () {
      samurai.___(4);
    }, Error, "Uh, this isn't good! Where'd ninja.yell go?");
  });

  it('a function is also an object, and can have properties', function () {
    var obj = {};
    var fn = function(){};
    obj.prop = "some value";
{'fraction_non_alphanumeric': 0.15260049533244427, 'fraction_numerical': 0.004381787007048962, 'mean_word_length': 3.0446841294298923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4861024', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1647, 'n_words': 538}