본문 바로가기

Algorithms

freeCodeCamp - 9. Finders Keepers [Basic Algorithm Scripting]

Finders Keepers

 

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers

 

www.freecodecamp.org

 

function findElement(arr, func) {
  for (let a of arr){
    if(func(a)) return a
  }
}

findElement([1, 2, 3, 4], num => num % 2 === 0);