Skip to content

Instantly share code, notes, and snippets.

@subhaze
Last active April 19, 2016 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subhaze/ff54ca5c9a05671c542be8d2684b1fed to your computer and use it in GitHub Desktop.
Save subhaze/ff54ca5c9a05671c542be8d2684b1fed to your computer and use it in GitHub Desktop.
concatAll [Array#reduce]
<pre style="padding: 20px"><code class="hljs js">
function concatAll(list){
return list.reduce((acc, curr) =>
acc.concat(curr)
, []);
}
console.log(concatAll([[1,2,3], [4,5,6]]));
// [1, 2, 3, 4, 5, 6]
</code></pre>
function concatAll(list){
return list.reduce((acc, curr) =>
acc.concat(curr)
, []);
}
console.log(concatAll([[1,2,3], [4,5,6]]));
hljs.initHighlightingOnLoad()
function concatAll(list){
return list.reduce(function(acc, curr){
return acc.concat(curr);
}, []);
}
// console.log(concatAll([[1,2,3], [4,5,6]]));
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/tomorrow-night-eighties.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment