Skip to content

Instantly share code, notes, and snippets.

@vishnuroshan
Created November 16, 2024 07:00
Show Gist options
  • Save vishnuroshan/50fc713f3bd3eb0ba225d3b3a8b9183f to your computer and use it in GitHub Desktop.
Save vishnuroshan/50fc713f3bd3eb0ba225d3b3a8b9183f to your computer and use it in GitHub Desktop.
Devi's solution to sort
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