Question:

Write the $$$.reject() function so the result variable is assigned to the array 'happy', 'joy'.

arr = ['happy', 'snakes', 'joy', 'slippers'];
result = $$$.reject(arr, function (word) {
  var last_letter = word[word.length - 1];
  return last_letter === "s";
});
console.log(result);

Answer:

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

Keywords:

© 2017 QuizBucket.org