find(elements, compareFct) {
Let 'i' equal to zero
Let 'len' equal to length of 'elements'
While 'i' is less than 'len'
Let 'nextElement' equal to the element in 'elements' at index 'i'
If (compareFct(nextElement))
Return i;
Let 'i' equal to 'i' plus 1
Return -1
}
function find(elements, compareFct) { let len = elements.length let i = 0 while (i < len) { let nextElem = elements[i] if (compareFct(nextElem)) return i i = i + 1 } return -1 } //Try It let nums = [2, 10, 20, 30, 31, 40, 41] //First num >= 20; let matchFct = (nextNum) => nextNum >= 20; let matchIndex = find(nums, matchFct); println("Match (>=20): " + nums[matchIndex]); //First odd num matchFct = (nextNum) => nextNum % 2 != 0 matchIndex = find(nums, matchFct); println("Match (first odd): " + nums[matchIndex]);