Improve commonAncestor by using a single loop instead of two shift()s

See http://jsperf.com/two-array-shift-vs-for