Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Created April 6, 2017 00:32
Show Gist options
  • Select an option

  • Save marcoslhc/a00b7357ead56af303aac42328da9123 to your computer and use it in GitHub Desktop.

Select an option

Save marcoslhc/a00b7357ead56af303aac42328da9123 to your computer and use it in GitHub Desktop.
array reduce concat
var arr = ['The', 'simple', 'things', 'of', 'life']
arr.reduce(function (finalString, str) {
return finalString.concat(' ').concat(str)
}, '');
// " The simple things of life"
// reduce folds the value from left to righ, we could also reduce from right to left:
var arr = 'stressed'.split('');
arr.reduceRight(function (finalString, str) {
return finalString.concat(str);
}, '');
// "desserts" The reversed string proves that the right most element was processed first and so on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment