As someone who uses Javascript all day, every day for work I realized I took a lot of basic algorithm tasks for granted so I have decided to dive i...
For further actions, you may consider blocking this person and/or reporting abuse
In some cases the best solution is the one use less operations to perform any task, some of them takes the memory usage, anyhow at least for this one you have to check the operations you are performing to solve this one.
I found something weird, is a bit complex to mentally process at first glance, anyhow it takes more steps that it should.
First:
You can create an "optimized solution cutting of some iterations"
This is just an experimental case, but in some cases it can crash the app or being unable to perform a task ;)
thanks!
I was trying to figure out how to efficiently implement different kinds of sorting algorithms in ES6 style and that's what I've came up with for bubble algorithm:
Basically, it's the same as yours, but it uses .map() method instead of for loop and destructuring to swap elements. It also uses 132 Operations, if testing like Marco showed here.
I just modified yours and was curious what would happen if I used ~500 random numbers, assigned to const and frozen... Using object.freeze alone makes a such a MASSIVE impact, I didn't realize...
Since an array starts from index 0. I would do this: