List
all
all( fn, array ) > Boolean
test all item in array with conditionnal function
const x = item => item > 42
const y = [43, 45, 46]
const z = [43, 45, 41]
all(x, y) //return true
all(x, z) //return false
any
any( fn, array ) > Boolean
test if one item valid conditionnal function
const x = item => item > 42
const y = [43, 45, 46]
const z = [43, 45, 41]
any(x, y)) //return true
any(x, z)) //return true
empty
empty( array ) > Boolean
test if array is empty
const x = []
const y = [1, 2, 3]
empty(x) //return true
empty(y) //return false
excludeDuplicate
excludeDuplicate( array ) > Array
return a new array without duplicate item
const x = [ 1, 2, 3, 4, 5 ]
const y = [ 4, 5, 6, 7, 8 ]
const z = [ 7, 8, 9, 10, 11 ]
const a = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
const b = [
{ name: 'dragon', attack: 10 },
{ name: 'kevin', attack: 3 },
{ name: 'jedi', attack: 6 }
]
excludeDuplicate(x, y, z) //return [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
excludeDuplicate(a, b)
/* return [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 },
{ name: 'kevin', attack: 3 },
{ name: 'jedi', attack: 6}
] */
filter
filter( fn, array) > Array
Currying filter array alias
const x = item => item > 42
const y = [ 43, 45, 46 ]
const z = [ 43, 45, 41 ]
const myfilter = filter(x)
filter(x, y) //return [ 43, 45, 46 ]
filter(x, z) //return [ 43, 45 ]
myfilter(z) //return [ 43, 45 ]
flatFilter
flatFilter( fn, array ) > Array
merge array and filter
const x = item => item > 45
const y = [ 43, 45, 46 ]
const z = [ 48, 45, 47 ]
flatFilter(x, [ y, z ]) //return [ 46, 48, 47 ]
flatMap
flatMap( fn, array ) > Array
merge array and transform
const x = item => item + 1
const y = [ 44, 45, 46 ]
const z = [ 47, 48, 49 ]
flatMap(x, [ y, z ]) //return [ 45, 46, 47, 48, 49, 50 ]
getDuplicate
getDuplicate( ...array ) > Array
get all duplicate items in arrays
const x = [ 1, 2, 3, 4, 5 ]
const y = [ 4, 5, 6, 7, 8 ]
const z = [ 7, 8, 9, 10, 11 ]
getDuplicate(x, y, z) //return [ 4, 5, 7, 8 ]
getDuplicate(x, z) //return []
getFirst
getFirst( ...array ) > Any | Array
Get first item in array. If you pass an array list getFirst return an array with all first item
const y = [ 44, 45, 46 ]
const z = [ 'Gandalf', 'Sauron', 'Bilbo' ]
getFirst(y) //return 44
getFirst(y, z) //return [ 44, 'Gandalf' ]
getLast
getLast( ...array ) > Any | Array
Get first item in array. If you pass an array list getLast return an array with all last item
const y = [ 44, 45, 46 ]
const z = [ 'Gandalf', 'Sauron', 'Bilbo' ]
getLast(y) //return 46
getLast(y, z) //return [ 46, 'Bilbo' ]
hasDuplicate
hasDuplicate(...array) > Boolean
test if arrays contains duplicate item. Return true if duplicate found
const x = [ 1, 2, 3, 4, 5 ]
const y = [ 4, 5, 6, 7, 8 ]
const z = [ 7, 8, 9, 10, 11 ]
hasDuplicate(x, z) //return false
hasDuplicate(x, y, z) //return true
map
map( fn, array) > Array
Currying map array alias
const x = item => item + 1
const y = [ 43, 45, 46 ]
map(x, y) //return [ 44, 46, 47 ]
pluck
pluck( property, array) > Array
return a value's array
const items = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
pluck('name', items) //return [ 'dragon', 'troll', 'gobelin' ]
removeItem
removeItem( item, array ) > Array
remove an item from array
const items = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
removeItem({ name: 'troll', attack: 5 }, items)
/* return
[
{ name: 'dragon', attack: 10 },
{ name: 'gobelin', attack: 1 }
]*/
removeIndex
removeIndex( index, array) > Array
remove item by index
const items = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
removeIndex(1, items)
/* return
[
{ name: 'dragon', attack: 10 },
{ name: 'gobelin', attack: 1 }
]*/
setFirst
setFirst( object, array ) > Array
Set item in first index
const x = [ 1, 2, 3, 4, 5 ]
const items = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
setFirst(4, x) //return [ 4, 1, 2, 3, 5 ]
setFirst({ name: 'troll', attack: 5 }, items)
/* return
[
{ name: 'troll', attack: 5 },
{ name: 'dragon', attack: 10 },
{ name: 'gobelin', attack: 1 }
]*/
setLast
setLast( object, array ) > Array
Set item in last index
const x = [ 1, 2, 3, 4, 5 ]
const items = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
setLast(4, x) //return [ 1, 2, 3, 5 ,4]
setLast({ name: 'troll', attack: 5 }, items)
/* return
[
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 },
{ name: 'troll', attack: 5 }
]*/
size
size(array) > Number
return array size
const x = []
const y = [ 1, 2, 3 ]
size(x) //return 0
size(y) //return 3
swap
swap( item1, item2, array ) > Array
swap item in array
const x = [ 1, 2, 3, 4, 5 ]
const items = [
{ name: 'dragon', attack: 10 },
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 }
]
swap(2, 4, x) //return [ 1, 4, 3, 2, 5 ]
swap({ name: 'troll', attack: 5 }, { name: 'gobelin', attack: 1 }, items)
/* return
[
{ name: 'troll', attack: 5 },
{ name: 'gobelin', attack: 1 },
{ name: 'troll', attack: 5 }
]*/
chunk
chunk(array, size) > Array
transform a one dimension array into multiple array with size length
const items = [ 1, 2, 3, 4, 5, 6 ]
chunk(items, 3)
/* return
[
[ 1, 2, 3 ],
[ 4, 5, 6 ]
]