Skip to content

Instantly share code, notes, and snippets.

@rfprod
Last active April 22, 2017 15:57
Show Gist options
  • Save rfprod/3156a61e7c6ad6e4fe3b to your computer and use it in GitHub Desktop.
Save rfprod/3156a61e7c6ad6e4fe3b to your computer and use it in GitHub Desktop.
Finders Keepers
function find(arr, func) {
var num = 0;
var passArr = [];
passArr = arr.filter(func);
num = passArr[0];
return num;
}
find([1, 2, 3, 4], function(num){ return num % 2 === 0; });

Finders Keepers

A function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument). If no elements pass a truth test, function returns 'undefined'.

A script by V.

License.

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