Skip to content

Instantly share code, notes, and snippets.

@trooperandz
Created May 31, 2018 21:03
Show Gist options
  • Save trooperandz/6a40aa09218b743252c2b000ed5edee8 to your computer and use it in GitHub Desktop.
Save trooperandz/6a40aa09218b743252c2b000ed5edee8 to your computer and use it in GitHub Desktop.
Custom some prototype
// Create our custom some function and attach it to the prototype
Array.prototype.customSome = function(callback) {
const arr = this;
for(let i = 0; i < arr.length; i++) {
if(callback(arr[i], i, arr)) return true;
}
return false;
}
// Execute our custom some function
const beachArr = ['waves', 'sharks', 'jellies', 'sand', 'pelicans'];
const customSomeResult = beachArr.customSome(item => item === 'sharks');
// true
console.log(`Our custom some result: ${customSomeResult}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment