Created
September 12, 2015 03:12
-
-
Save ericcgu/be59c5e7d2b7843509ae to your computer and use it in GitHub Desktop.
Where do i belong
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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