Answers for "Demonstrate insertion Sort javascript and explain when you might use it?"

3

insertion sort javascript

let insertionSort = (inputArr) => {
    for (let i = 1; i < inputArr.length; i++) {
        let key = inputArr[i];
        let j = i - 1;
        while (j >= 0 && inputArr[j] > key) {
            inputArr[j + 1] = inputArr[j];
            j = j - 1;
        }
        inputArr[j + 1] = key;
    }
    return inputArr;
};
Posted by: Guest on September-04-2020

Code answers related to "Demonstrate insertion Sort javascript and explain when you might use it?"

Code answers related to "Javascript"

Browse Popular Code Answers by Language