Created
July 27, 2015 15:51
-
-
Save alexandrebvd/4cbfd46481baffb9a6f1 to your computer and use it in GitHub Desktop.
18.Bonfire: Where do I belong
This file contains 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) { | |
newArr = arr.sort(); | |
finalArr = []; | |
for (var i = 0; i < newArr.length; i++) { | |
if (num > newArr[i] && num < newArr[i+1]) { | |
finalArr.push(newArr[i]); | |
finalArr.push(num); | |
} else { | |
finalArr.push(newArr[i]); | |
} | |
} | |
return finalArr.indexOf(num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment