Skip to content

Instantly share code, notes, and snippets.

@EliecerC
Created December 19, 2018 03:26
Show Gist options
  • Save EliecerC/40510aa95c7cfd2204251145a262c53e to your computer and use it in GitHub Desktop.
Save EliecerC/40510aa95c7cfd2204251145a262c53e to your computer and use it in GitHub Desktop.
Array Flatten JavaScript
'use strict';
Array.prototype.flatten = function(array) {
var flattened = [];
var getItemValue = function(item) {
Array.isArray(item)
? item.map(getItemValue)
: flattened.push(item);
};
this.map(getItemValue);
return flattened;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment