1.1.5 • Published 7 years ago

array2-dconvert v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

Installation

This module works on node and in the browser. It is available as the 'array2dconvert' package on npm. It is also available on a CDN.

npm

npm install  --save array2-dconvert

Usage

let Array2d = require("array2-dconvert");
let array = new Array2d();
let row = 2;
let col = 2;
let array2d = array.createArray(row, col);
for(let i=0;i<row;i++) {
    for(let j=0;j<col;j++) {
        array2d[i][j]=0;
    }
}
console.log(array2d);

API

array.createArray(row, col)

returns an 2-d array with size row x col.

array.convertTo2d(data1, data2, data3, data4, .........)

combine the multiple 1-d array given in the input (data1, data2, data3, data4, ........) into one and return 2-d array.

array.convertTo1d(data)

split one 2-d array (data) and return multiple 1-d array.

Example

let data1 = [1,2,3,4,5,5,6,7,8];
let data2 = [11,12,13,14,15,13,12,12,12];
let data3 = [3,4,5,8,9,00,87,67,56];
let resultarray2d = array.convertTo2d(data1,data2,data3);
console.log(resultarray2d);
let data = [[1,2],[3,4],[5,6],[7,8]];
let resultarray1d = array.convertTo1d(data);
let rdata1 = resultarray1d[0];
let rdata2 = resultarray1d[1];
console.log(rdata1);
console.log(rdata2);

Development

  • Install the dependencies with npm install