Javascript Array Question 24

Introduction

Greater Than Y

Count the number of array values greater than a given value Y.


function greater_than_y(arr, y) {
  var count = 0;
  //code here
  return count;
}
greater_than_y([2,3,0], 1);




function greater_than_y(arr, y) {
  var count = 0;
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] > y) {
      count++;
    }
  }
  return count;
}
greater_than_y([2,3,0], 1);



PreviousNext

Related