1.0.0 • Published 9 years ago

2d-array v1.0.0

Weekly downloads
103
License
ISC
Repository
github
Last release
9 years ago

2d-array

Transform a 1d array into a 2d array

build status

Installation

npm install 2d-array --save

Usage

var create2dArray = require('2d-array')

console.log(create2dArray([ 1, 2, 3, 4, 5, 6 ], 2))
// -> [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]

console.log(create2dArray([ 1, 2, 3, 4], 2, 2))
// -> [ [ 1 ], [ 2, 3 ] ]

var array = create2dArray(array, n[, ignore])

Options must include:

  • array - an array to transform into a 2d array.
  • n - the number of items to be inside each array. Non-numbers (undefined, null, ''), Non-floats or strings that represent anything other than one number will return an empty array.
  • 'ignore' - Optional - When set, deletes the value specified from any array containing that value.

Credits