Freecodecamp: Drop it : Test case 2 and 6 expect wrong return value from the function.

Created on 29 Nov 2016  ·  3Comments  ·  Source: freeCodeCamp/freeCodeCamp

Challenge Drop it has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function dropElements(arr, func) {
  // Drop them elements.
  var duplicateArr = [];
  for(var i = 0 ; i < arr.length; i++){
    if(func(arr[i])){
      duplicateArr.push(arr[i]);
    }
  }
  return duplicateArr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });

Incorrect Test Cases
dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1] - actual return value [1, 1]

dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2] - actual return value [3, 9]

Most helpful comment

@pdhanoya You're to drop the items in the array, starting with index 0 until the function becomes true, NOT to drop all the items in the array that do not make the function (second argument) true. I see how it could be misunderstood.

All 3 comments

@pdhanoya You're to drop the items in the array, starting with index 0 until the function becomes true, NOT to drop all the items in the array that do not make the function (second argument) true. I see how it could be misunderstood.

@pdhanoya as @dhcodes has pointed out, the instructions say to drop elements until the function is true.

Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.

Thus, the tests and instructions are consistent with each other. If you get stuck or have questions with a challenge in the future, please first ask questions to the Help Room. Happy coding!

I had the same query. Thanks for the clear answer.

Was this page helpful?
0 / 5 - 0 ratings