Question:

Write a function that satisfies the following console.log assertions.

var callback = function (num) {
  return num % 2 === 0
}

console.log($$$.any([1, 3, 4], callback) === true)
console.log($$$.any([1, 11, 111], callback) === false)

Answer:

$$$ = {
  any: function (arr, callback) {
    for (var i = 0, l = arr.length; i < l; i ++) {
      if (callback(arr[i])) {
        return true;
      }
    }
    return false;
  }
}

Keywords:

© 2017 QuizBucket.org