Skip to content

Instantly share code, notes, and snippets.

@AppWerft
Last active August 29, 2015 14:02
Show Gist options
  • Save AppWerft/74c4c675f6191dfd0fc4 to your computer and use it in GitHub Desktop.
Save AppWerft/74c4c675f6191dfd0fc4 to your computer and use it in GitHub Desktop.
Array.prototype.contains
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
Copy link

easy, right? 😸

@AppWerft
Copy link
Author

Yes it is. The code avoids a deadlock.

@AppWerft
Copy link
Author

But – "process.nextTick":what it is? A new JS command?

@AppWerft
Copy link
Author

@greelgorke
Copy link

you could also use setTimeout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment