Skip to content

Instantly share code, notes, and snippets.

View ghmcadams's full-sized avatar

Gabriel McAdams ghmcadams

View GitHub Profile
@ghmcadams
ghmcadams / flattenArray.js
Created April 30, 2016 15:36
Flatten an integer array in JavaScript
function flattenIntegerArray(array) {
var ret = [];
for (var i = 0; i < array.length; i++) {
if (Array.isArray(array[i])) {
//Add items from the sub array into the returned array
Array.prototype.push.apply(ret, flattenIntegerArray(array[i]));
} else if (Number.isInteger(array[i])) {
ret.push(array[i]);
} else {
// In JavaScript, you can't guarantee that the type