Created
May 31, 2018 21:05
-
-
Save trooperandz/6cdf2ab0f9d58cea6306a3bb99256b38 to your computer and use it in GitHub Desktop.
Custom every prototype
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
// 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