Skip to content

Instantly share code, notes, and snippets.

View iambateman's full-sized avatar

Stephen Bateman iambateman

View GitHub Profile
@iambateman
iambateman / flattenArray.ts
Created January 3, 2018 14:59
Flatten arbitrary array of numbers in Typescript / Angular
testArray:Array<any> = [10, [9,8,7],6, [5, [4,3,2], 1], 10,9,8];
flatten(list:Array<any>) {
let flattened:Array<number> = [];
// For each item in the provided list, check to see if it's a number.
// if it's not, recurse with the sub-array and add those items.
for (let item of list) {
if (typeof item === "number") {
flattened.push(item);