Shorter stableSort function + use const
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
var stableSort = (arr, compare) =>
|
||||
const stableSort = (arr, compare) =>
|
||||
arr
|
||||
.map((item, index) => ({ item, index }))
|
||||
.sort((a, b) =>
|
||||
((result = compare(a.item, b.item)) => (result !== 0 ? result : a.index - b.index))()
|
||||
)
|
||||
.sort((a, b) => compare(a.item, b.item) || a.index - b.index)
|
||||
.map(({ item }) => item);
|
||||
module.exports = stableSort;
|
||||
Reference in New Issue
Block a user