JSFiddle - React, Tailwind, and code Playground

JavaScript

alert(insertionSort("What needs to be done first", ["finish homework", "finish chores", "go shopping"]));

function promptInput(comparison, str1, str2){
    return prompt(comparison + ": "+str1+ " or " + str2 + "?");
}

//alert(promptInput("finish homework", "finish fractal project"));

//Programmer: Larry Battle Mar 9, 2011
//Purpose: Insertion sort implemented in Javascript.
function insertionSort(comparison, arr) {
    var len = arr.length, i = -1, j, tmp;
 
    while (len--) {
        tmp = arr[++i];
        j = i;
        while (j-- && (promptInput(comparison, arr[j], tmp) == arr[j])) {
            arr[j + 1] = arr[j];
        }
        arr[j + 1] = tmp;
    }
    return arr.reverse();
}