Created
November 16, 2024 07:00
-
-
Save vishnuroshan/50fc713f3bd3eb0ba225d3b3a8b9183f to your computer and use it in GitHub Desktop.
Devi's solution to sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortBy(arr, fn= ()=>{}) { | |
const array = [...arr]; | |
for (let i=0; i<array.length; i++) { | |
for (let j=i+1;j<array.length;j++){ | |
if (array[j] < array[i]) { | |
const temp = array[i]; | |
array[i] = array[j]; | |
array[j] = temp; | |
} | |
} | |
} | |
return array; | |
}; | |
const rr = sortBy([34,12,67,1,2,9,5,3], (x)=>x); | |
console.log(rr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment