Do you understand the comments?

Hi guys,

Just read the solution to a problem in JavaScript and tell me if you understand the
comment.
can u understand the logic and problem from the comments?
Intermediate algorithms JavaScript challenge Dropit

function dropElements(arr, func) {
    let index=null;
    //loop through arr
    for(var i=0; i<arr.length; i++){
      let number=Number(arr[i]); //convert element to number
      //pass array element to function
      if(func(number)) //if the number statisfy the condition it return true or false
      {
          index =i;    //find first index of element for which it is true
          break;       //first true element then break
      }
    }
    //console.log(index);
    if(index === null){  //if no element in arr statisfy the function return empty array
        return [];
    }
    return arr.slice(index,arr.length); //return the array from the first element that statisfy the condition
  }
 console.log(dropElements([1, 2, 3], function(n) {return n < 3; }));
 console.log(dropElements([1, 2, 3, 4], function(n) {return n >= 3;}));
 console.log(dropElements([0, 1, 0, 1], function(n) {return n === 1;}));
 console.log(dropElements([1, 2, 3], function(n) {return n > 0;}));
 console.log(dropElements([1, 2, 3, 4], function(n) {return n > 5;}));
 console.log(dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;}));
 console.log(dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}));

if i cant post full solution i will make edits!!

is my comments ok… can another programmer read and understand my solution?

My 2 cents would be - comments don’t need to tell WHAT you are doing, should tell WHY you are doing.
e.g.,//convert element to number

let number=Number(arr[i]); 

Its fairly obvious - instead maybe you can comment:
// I need the user input(string) converted to number to process… etc.

Just what i feel - otherwise you don’t understand the INTENT of the programmer.

2 Likes