Skip to content

Instantly share code, notes, and snippets.

@ericcgu
Created September 12, 2015 03:12
Show Gist options
  • Save ericcgu/be59c5e7d2b7843509ae to your computer and use it in GitHub Desktop.
Save ericcgu/be59c5e7d2b7843509ae to your computer and use it in GitHub Desktop.
Where do i belong
function where(arr, num) {
// Find my place in this sorted array.
console.log(getMax(arr))
if (num > getMax(arr)){
console.log(getMax(arr))
return arr.length
}
var sortedArray = arr.sort(function(a,b){return a > b});
for (var obj in sortedArray) {
var i = Object.keys(sortedArray).indexOf(obj);
if (sortedArray[i] >= num){
return i;
}
}
function getMin(array){
return Math.min.apply(Math,array);
}
function getMax(array){
return Math.max.apply(Math,array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment