Skip to content

Instantly share code, notes, and snippets.

@Yrds
Last active May 21, 2020
Embed
What would you like to do?
const vect = [1, 2, 3, 4, 5, 6, 7, 8];
const evenNumbers = vect.filter(number => number % 2 == 0);
console.log(evenNumbers); //[2, 4, 6, 8]
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> vect { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::vector<int> evenNumbers;
std::copy_if(vect.begin(), vect.end(), std::back_inserter(evenNumbers),
[](int number){return number % 2 == 0;});
for(auto number: evenNumbers)
std::cout << number << " "; //2 4 6 8
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment