Created
June 25, 2015 23:49
-
-
Save vermie/79eeaed5ab048c8d2004 to your computer and use it in GitHub Desktop.
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
function hasIndex(array, index) { | |
return array.splice(index, 1).reduce(function () { | |
return true; | |
}, false); | |
} | |
var array = []; | |
hasIndex(array, 0); // => false | |
array[0] = 1; | |
hasIndex(array, 0); // => true | |
array[0] = undefined; | |
hasIndex(array, 0); // => true | |
array[2] = 1; | |
hasIndex(array, 1); // => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment