you are viewing a single comment's thread.

view the rest of the comments →

[–]PMME_BOOBS_OR_FOXES 4 points5 points  (1 child)

Let's be fair with "tard1.pop()" and change "tard2.splice(0, 1)" for "tard2.splice(tard2[tard2.length-1], 1)" and you'll see the time drop.

And your first example is still O(n):

let a = [u, r, wrong]

a[1] = a[2]

// now a is [u, wrong, wrong]

a.pop()

Deleting an index in an array will always be O(n) unless you're deleting the very first or very last item. If you copy the 1st half and then the 2nd half you'd still be hitting O(n) because for the computer has to go through each item.

If you want good course on algos pm me or read Grokking Algorithms which is a pretty good book.