Where do I belong challenege, why does my code suck?

Hey, guys and gals, I was just wondering if you could offer any tips with this code! I know it’s super bad because I feel like I brute forced the answer. I didn’t look anything up besides the documentation examples of course since I’m trying my best to think on my own. I have to admit that I’m struggling a bit with these “basic” challenges, haha!

function getIndexToIns(arr, num) {
  var args = Array.prototype.slice.call(arguments);
  var newArray = args.toString().split(',');
  newArray.sort(function(a,b) {
    return a - b;
  function butWhy(element) {
    return element == num;
  return newArray.findIndex(butWhy);

I could nitpick, but there’s nothing horrible about your code. Maybe try to solve it without using findIndex.

Also, I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like

Thanks a bunch! I was wondering how to do that before I posted, haha. I should have looked a little harder I guess! I’ll try doing what you said to get to the solution.