I am currently working through Khan Academy\'s algorithm course, which uses JS to teach fundamental algorithms. I am currently in the process of implementing an insertion so
This has worked:
var insert = function(array, rightIndex, value) {
var j = rightIndex; for(var j = rightIndex; j >= 0 && array[j] > value; j--) { array[j + 1] = array[j]; } array[j + 1] = value;