<commit_before>
// run like so:
// mocha -R spec Craziness/yep.js

// ===============================================================================
// HUGE DISCLAIMER AND WARNING:
// Don't be an interview jerk and ask questions like "What does {} + [] returns?".
// That's just mean.
// ===============================================================================

var assert = require('assert');

describe ('Crazy take #1', function () {
  it('{} + [] === ?', function () {
    assert({} + [] !== false);
    assert({} + [] !== true);
  });

  it('[] + 12', function () {
    assert([] + 12 === "12");
    assert.equal(typeof ([] + 12), 'string');
  });

  it('{} + 12', function () {
    assert({} + 12 !== "12");
  });

  it ('new Boolean(false) === ?', function () {
    var b = new Boolean(false);
    assert.equal(b.valueOf(), false);
    assert.equal(b.toString(), "false");

    // now, let's use it. It doesn't evaluate to false!!!
    assert(b ? 'true' : 'false' !== 'false');
  });
});
<commit_msg>craziness coersion<commit_after>
// run like so:
// mocha -R spec Craziness/yep.js

// ===============================================================================
// HUGE DISCLAIMER AND WARNING:
// Don't be an interview jerk and ask questions like "What does {} + [] returns?".
// That's just mean.
// ===============================================================================

var assert = require('assert');

describe ('Crazy take #1', function () {
  it('{} + [] === ?', function () {
    assert({} + [] !== false);
    assert({} + [] !== true);
  });

  it('[] + 12', function () {
    assert([] + 12 === "12");
    assert.equal(typeof ([] + 12), 'string');
  });

  it('{} + 12', function () {
    assert({} + 12 !== "12");
  });

  it ('new Boolean(false) === ?', function () {
    var b = new Boolean(false);
    assert.equal(b.valueOf(), false);
    assert.equal(b.toString(), "false");

    // now, let's use it. It doesn't evaluate to false!!!
    assert(b ? 'true' : 'false' !== 'false');
  });

  it('integers, anyone?', function () {
    var a = 0;
    var b = new Number(0);
    assert.equal(a == b, true);
    assert.equal(!!a == !!b, false); // this is crazy!
    assert.equal(!!a, false);
    assert.equal(!!b, true);
  });

  it('converts anything to a string...', function () {
    assert.equal('' + false, 'false');
  });
  it('  ...or a number', function () {
    assert.equal(true + true, 2);
    assert.equal(true << true, 2);
  });

  it('coersion madness', function () {
    assert.equal( []  === 0, false); // yep, expected, right?
    assert.equal(+[]  === 0, true);  // wow
    assert.equal(+[8] === 8, true);  // wow
  });

  it('valueOf crap', function () {
    var valueOfCalled = false;
    var O = function () {this.valueOf = function () {valueOfCalled = true; return false;};};
    var o = new O();

    // initially, no coersion happened:
    assert.equal(valueOfCalled, false);


    // numeric coescion happens:
    assert.equal(+o, false);
    assert.equal(valueOfCalled, true);
    valueOfCalled = false; // reset the flag

    // and now no coersion!
    assert.equal(!!o, true);
    assert.equal(valueOfCalled, false);

    // in other words,
    assert.equal(!!o !== +0, true);
  });
});

{'fraction_non_alphanumeric': 0.3021826006762988, 'fraction_numerical': 0.011988933292345526, 'mean_word_length': 3.1505102040816326, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6838476', 'n_tokens_mistral': 1068, 'n_tokens_neox': 980, 'n_words': 274}