Skip to content

Instantly share code, notes, and snippets.

View BenShelton's full-sized avatar
🏠
Working from home

Ben Jones BenShelton

🏠
Working from home
  • Freelancer
  • Cardiff, Wales
View GitHub Profile
@BenShelton
BenShelton / flatten.js
Created February 23, 2017 16:50
Flatten a Nested Array
/* flatten function
Accepts an n-dimensional array
as an argument and returns a
1-dimensional array
Returns value for non-arrays
Uses recursion to drill down
into each array section
*/
function flatten(val) {
// if not an array returns value