lib array old export

This commit is contained in:
tmshv committed 2019-08-01 14:39:10 +03:00
1 parent d8cf5c7525
commit dcca513aea
1 file changed
+11 -11
+11 -11
View File
@@ -1,26 +1,26 @@
function splitBy(key) { export function splitBy(fn) {
return items => { return items => {
return items.reduce((acc, item) => { return items.reduce((acc, item) => {
const name = key(item) const key = fn(item)
const items = acc.get(name) || [] const items = acc.get(key) || []
return acc.set(key(item), [...items, item]) return acc.set(key, [...items, item])
}, new Map()) }, new Map())
} }
} }
function head(list) { export function head(list) {
return Array.isArray(list) && list.length return Array.isArray(list) && list.length
? list[0] ? list[0]
: null : null
} }
function last(list) { export function last(list) {
return Array.isArray(list) && list.length return Array.isArray(list) && list.length
? list[list.length - 1] ? list[list.length - 1]
: null : null
} }
exports.splitBy = splitBy // exports.splitBy = splitBy
exports.head = head // exports.head = head
exports.last = last // exports.last = last