Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.
Wessel T edited this page Jan 24, 2019 · 1 revision

Array Utilities

nabbit.chunk(array, length): Array

  • array (Array) - The array to chunk down
  • Length (Number) - The maximum length of every chunk

Splits an array into multiple array specified with the size argument If array can't be split evenly, the final chunk will be the remaining elements

nabbit.chunk([ 'a', 'b', 'c', 'd' ], 2)
// => [[ 'a', 'b' ], [ 'c', 'd' ]]
 
nabbit.chunk([ 'a', 'b', 'c', 'd' ], 3)
// => [[ 'a', 'b', 'c' ], [ 'd' ]]

nabbit.list(array, splitter, conj): String

  • array (Array) - The array to list
  • splitter (String) - The splitter between every element
  • conj (String) - The last splitter

Join an array together with a custom splitter and a conjoin at the end

nabbit.list( [ 1, 2, 3 ], ', ', 'and' )
// => 1, 2 and 3

nabbit.scramble(array): Array

  • array (Array) - The array to scramble

Rerearrange every entry in array to a random position

nabbit.scramble([ 1, 2, 3 ])
// => [ 3, 1, 2 ]

nabbit.scramble( 'Hello'.split( '' ) ).join( '' )
// => elHlo

Clone this wiki locally