Discussion on: What’s your alternative solution? Challenge #45

jithinks97 profile image
Jithin KS

Wow, thanks for the response.

  • I really would like to understand how arrow function costs performance because currently, I don't use the function syntax anywhere. I consider the arrow function as the function in JS. I really need to know if I want to change that habit.

  • I'm well aware that the algorithm does not have a terminating condition if its already sorted, I just didn't want to make it more complicated.

  • Yes, I do agree about the swap, what you said is more suitable there.

Thread Thread
miketalbot profile image
Mike Talbot

So arrow functions make a class that captures the current "this" and provide it through to the inner function. It's not a massive cost, but it's additional to the cost of calling a function in both memory and instructions. It makes total sense if you need the "this" and indeed all functions declared in the body of another create a class to carry around the bound closure variables - but there is no such cost for a globally defined function.

Declaring any const requires that the code is executed before using the variable.

This works:


     function doSomething() { console.log('ok'); }

This does not:

     const doSomething = ()=>console.log("Nope!");