Where do I belong exercise - request feedback (not help)

Hi all,

As I move through the exercises, I am trying to pay more attention to observations about processing time and efficient code. After I finished my solution I saw that many others chose to skip the sort, so I feel happy about realizing that.

I am mainly curious whether my use of reduce is considered code abuse or if it is an acceptable use of that function?

Thank you!


function getIndexToIns(arr, num) {
  return arr.reduce(function(x,y){
    if (y<num) return x+=1;
    else return x;
  },0);
}

getIndexToIns([40, 60], 50);

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

1 Like

Oops - thank you for the heads-up!

Fascinating! Thanks for introducing me to arrow notation for functions, @camperextraordinaire. I also see your point about clarity in variable names.

Sorry about the spoiler tags! Thanks for fixing and pointing that out to me.