Skip to content

Instantly share code, notes, and snippets.

View ravi0402's full-sized avatar
🎯
Focusing

Ravi S ravi0402

🎯
Focusing
View GitHub Profile
@ravi0402
ravi0402 / flatten.js
Last active September 9, 2019 20:30
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
const arrayFlatten = (arr) => {
if (!Array.isArray(arr))return 'The input provided is not an array';
return arr.reduce((x, y) => {
if (Array.isArray(y)) return x.concat(arrayFlatten(y));
return x.concat(y)
}, [])
}