complete insertion sort implementation in js