정렬

Javascript sort method

function sortCustom(arr) {
    return arr.sort(conditionFunction());
}

Selection sort using Javascript

function selectionSort(arr) {
    let tempArr = arr.slice();
    for (let i = 0; i < tempArr.length; i++) {
        let minIndex = i;
        for (let j = i; j < tempArr.length; j++) {
            if (tempArr[minIndex] > tempArr[j]) {
                minIndex = j;
            }
        }
    
        if (minIndex !== i) {
            let temp = tempArr[i];
            tempArr[i] = tempArr[minIndex];
            tempArr[minIndex] = temp;
        }
    }
    
    return tempArr;
}

Condition Function

Last updated