JavaScript. bubbleSort

JavaScript. bubbleSort
0

Hi all. I need to solve this coding challenge.
Get the values of inputs and sort it from lowest to highest.

Code here!;

But seems that there is a bug…
Actually -9 > -999. But my code don’t work correct when it comes to -numbers.
How can I solve this probleem?

I don’t see any problem with your code if your intention is to sort in ascending order

I don’t quite know what you mean but -999 is not greater than -9

Ohh sorry. Mistake…
I mean -9 is greater than -999. Right?

Yes -9 is greater than -999 and that is what your add does (puts -999 before -9), doesn’t it?

Yes yes. Sorry my bed…

:grinning: :grinning: :grinning: :grinning: Happy coding.

It seems that in the codepen that warks fijn. But when I run it locally it crashes

This is exactly the same code.

Try changing the items you push into the array to number like
inputsArray.push(+item.value);

Super :+1:It works now correct!!
Thanks!

1 Like