Skip to content

Instantly share code, notes, and snippets.

@raloliver
Last active July 1, 2019 17:42
Show Gist options
  • Save raloliver/4666321f1accb2403ca7a385b0de0267 to your computer and use it in GitHub Desktop.
Save raloliver/4666321f1accb2403ca7a385b0de0267 to your computer and use it in GitHub Desktop.
Imperativa x Funcional
/*Programação Imperativa*/
var list = [1,2,3,4,5,6];
var pares = [];
for(var i = 0; i < list.length; i++){
if(list[i] % 2 === 0){
pares.push(list[i]);
}
}
/* Programação Funcional */
var list = [1,2,3,4,5,6];
var pares = list.filter(x => x % 2 === 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment