We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Calm down, bud. This is a practice problem, you know. It's not meant to be an open-ended challenge. In other words, we are trying to implement insertion sort using “the” insertion algorithm, or, at the very least, an algorithm that has the same performance.
In js, shifting requires a bunch of in-place modifications within one iteration, while Array.slice requires scanning/bsearching for the right index and creating two tmp arrays and concatenating them. I wouldn't call that efficient. Depending on your memory allocator, your algorithm might even run asymptotically slower than the already slow insertion sort.
And it doesn't even make your code shorter... So why use it anyways?
I'm sorry but I have to downvote...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
Calm down, bud. This is a practice problem, you know. It's not meant to be an open-ended challenge. In other words, we are trying to implement insertion sort using “the” insertion algorithm, or, at the very least, an algorithm that has the same performance.
In js, shifting requires a bunch of in-place modifications within one iteration, while
Array.slice
requires scanning/bsearching for the right index and creating two tmp arrays and concatenating them. I wouldn't call that efficient. Depending on your memory allocator, your algorithm might even run asymptotically slower than the already slow insertion sort.And it doesn't even make your code shorter... So why use it anyways?
I'm sorry but I have to downvote...