Skip to content

Instantly share code, notes, and snippets.

View arosca's full-sized avatar

Andrei Rosca arosca

  • Bucharest, Romania
View GitHub Profile
@arosca
arosca / flatten.ts
Last active January 5, 2020 08:47
Flatten an array of nested arrays of integers
const { expect } = require('chai');
/**
* Flattens nested arrays
* @param {Array} array The array to flatten.
* @returns {Array} Returns the new flattened array.
*/
const flatten = (arr: Array<any>): Array<number> => arr.toString().split(',').map(x => parseInt(x, 10)).filter(x => !!x) || [];
describe('flatten', () => {