Skip to content

Instantly share code, notes, and snippets.

@guz-anton
Created June 27, 2017 04:38
Show Gist options
  • Select an option

  • Save guz-anton/a29048d25860769f77d9eabf09ffc502 to your computer and use it in GitHub Desktop.

Select an option

Save guz-anton/a29048d25860769f77d9eabf09ffc502 to your computer and use it in GitHub Desktop.
A set of method to flatten arrays
const makeFlat = (array) => {
return array.reduce((all, current) => {
return Array.isArray(current)
? all.concat(makeFlat(current))
: all.push(current) && all;
},[]);
};
expect(makeFlat([[1,2,[3]],4])).toEqual([1,2,3,4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment