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