Skip to content

Instantly share code, notes, and snippets.

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