Skip to content

Instantly share code, notes, and snippets.

@f1lander
Last active September 10, 2019 02:43
Show Gist options
  • Save f1lander/d06700835436d20db6b8c162d1f1441f to your computer and use it in GitHub Desktop.
Save f1lander/d06700835436d20db6b8c162d1f1441f to your computer and use it in GitHub Desktop.
/**
Example Code for developer position application
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
For this code I'll use JS (es6) running in NodeJS v11
Instructions:
0. Download the file
1. Open the Terminal
2. run -> node EdaxFlattenArray.js
**/
// declare the array that we need to flatten
const array = [[1, 2, [3]], 4];
// function in charge to flatten the array
const flatten = array => array.toString().split(',').map(item => !isNaN(parseInt(item)) ? parseInt(item) : item);
// log the result of the flatten array
console.log(flatten(array));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment