Question:

Write the $$$.find() function so the result variable is assigned to the string "cat".

arr = ['ant', 'cat', 'dog']
result = $$$.find(arr, function(str) {
  return str[0] === "c";
});
console.log(result);

Answer:

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

Keywords:

© 2017 QuizBucket.org