Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
};
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #insertion #sort #javascript
ADD COMMENT
Topic
Name
2+8 =