Created
July 16, 2015 11:03
-
-
Save cjdell/3822fd330859fcc5aa0b to your computer and use it in GitHub Desktop.
Strange indexOf issue with large arrays. Works in some runtimes and not others (node)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run this script with Node.js to see it throw. Works fine in browsers for some reason. Maybe an optimisation bug | |
function loop() { | |
var arr = [0]; | |
var i = 0; | |
//eval('(1)'); // ==== UNCOMMENTING THIS MAKES IT WORK | |
while (i < 4101) { // ==== MAKING THIS SMALLER MAKES IT WORK | |
var num = (i % 2) / 2; // ==== SIMPLIFYING THIS MAKES IT WORK | |
//console.log(num); | |
if (arr.indexOf(num) !== Array.prototype.indexOf.call(arr, num)) { | |
console.log('i', i); | |
console.log('num', num); | |
throw new Error('WTF this should not happen!'); | |
} | |
i++; | |
} | |
} | |
loop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment