Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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