Question:

Write the $$$.select() function so the result variable is assigned to the array [5, 7, 9].

arr = [5, 6, 7, 8, 9];
result = $$$.select(arr, function(num) {
  return num % 2 === 1;
});
console.log(result);

Answer:

$$$ = {
  select: function(arr, callback) {
    result = [];
    arr.forEach(function (num) {
      if (callback(num)) {
        result.push(num);
      }
    });
    return result;
  }
}

Keywords:

© 2017 QuizBucket.org