Skip to content

Instantly share code, notes, and snippets.

@Yrds
Created May 21, 2020 00:11
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 Yrds/5391af765e722b685973bb044d8824c5 to your computer and use it in GitHub Desktop.
Save Yrds/5391af765e722b685973bb044d8824c5 to your computer and use it in GitHub Desktop.
const vect = ['h','e','l','l','o',' ','w','o','r','l','d'];
const newString = vect.reduce((acc, character) => acc.concat(character));
console.log(newString); //hello world
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
int main(){
std::vector<char> vect {'h','e','l','l','o',' ','w','o','r','l','d'};
std::string result = std::accumulate(vect.begin(), vect.end(), std::string(),
[](std::string acc, char character){return acc + character;});
std::cout << result; //hello world
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment