deno.land / x / rambda@v9.1.1 / source / sortByProps.js

sortByProps.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { path } from './path.js'
function singleSort( a, b, sortPaths){ let toReturn = 0 sortPaths.forEach(singlePath => { if (toReturn !== 0) return const aResult = path(singlePath, a) const bResult = path(singlePath, b) if ([ aResult, bResult ].includes(undefined)) return if (aResult === bResult) return
toReturn = aResult > bResult ? 1 : -1 })
return toReturn}
export function sortByProps(sortPaths, list){ if (arguments.length === 1) return _list => sortByProps(sortPaths, _list) const clone = list.slice()
clone.sort((a, b) => singleSort( a, b, sortPaths ))
return clone}
rambda

Version Info

Tagged at
2 months ago