You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
510 B

function sortHelper(
a, b, listOfSortingFns
){
let result = 0
let i = 0
while (result === 0 && i < listOfSortingFns.length){
result = listOfSortingFns[ i ](a, b)
i += 1
}
return result
}
export function sortWith(listOfSortingFns, list){
if (arguments.length === 1)
return _list => sortWith(listOfSortingFns, _list)
if (Array.isArray(list) === false)
return []
const clone = list.slice()
clone.sort((a, b) => sortHelper(
a, b, listOfSortingFns
))
return clone
}