Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, May 12, 2017

FreeCodeCamp Where Do I Belong Sample Solution



function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var sorted = arr.sort(function(a, b){return a-b});
  for(var i=0; i<sorted.length; i++){
    if(num > sorted[sorted.length-1]){
      return sorted.length;
    }
    if(sorted[i] >= num){
      return i;
    }  
  }
}

getIndexToIns([5, 3, 20, 3], 5);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts