Last active
August 29, 2015 14:02
-
-
Save AppWerft/74c4c675f6191dfd0fc4 to your computer and use it in GitHub Desktop.
Array.prototype.contains
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
Array.prototype.contains = function(k, callback) { | |
var self = this; | |
return (function check(i) { | |
if (i >= self.length) { | |
return callback(false); | |
} | |
if (self[i].id === k.id) { | |
return callback(true); | |
} | |
return process.nextTick(check.bind(null, i+1)); | |
}(0)); | |
} |
greelgorke
commented
Jun 11, 2014
easy, right? 😸
Yes it is. The code avoids a deadlock.
But – "process.nextTick":what it is? A new JS command?
you could also use setTimeout
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment