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.
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; }); |