Noob here and I am kind of wondering. Why this (snippy follows):
const sortedValues = inputValues.sort((a, b) => {
return a-b;
});
And not this:
const sortedValues = inputValues.sort((a,b) a-b);
The second is short and sweet? I kind of grasp the first one, since it is shown in the Array.prototype.sort() in mdn Web Docs explanation, no I didn’t read it all the way, I just scanned as fast as my noob squirrel brain dictates. I mean I could ask the ChatJippy for something, but I would love to here some opins.
Thanks in advance and please forgive my noobishness.
inputValues.sort((a, b) => {
return a-b;
});
inputValues.sort((a, b) => a-b);
The difference is that the return is implicit in the second case, when you exclude the curly braces. This is useful for concise, single-line expressions. However, If you need a code block when using arrow syntax, you need to include both the curly braces and the return keyword.