Skip to content

Instantly share code, notes, and snippets.

@justincorrigible
Created December 4, 2015 03:53
Show Gist options
  • Save justincorrigible/6489cf2c571e4449b2b1 to your computer and use it in GitHub Desktop.
Save justincorrigible/6489cf2c571e4449b2b1 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/hallaathrad 's solution for Bonfire: Where do I belong
fire-where-do-i-belong.js
// Bonfire: Where do I belong
// Author: @hallaathrad
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
arr.push(num);
return arr.sort(function(x,y){return x<y?-1:x>y?1:0;}).indexOf(num);
}
where([40, 60], 50);
@justincorrigible
Copy link
Author

Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment