Skip to content

Instantly share code, notes, and snippets.

@alanyoshida
Created July 30, 2016 19:35
Show Gist options
  • Save alanyoshida/2e5d8c5682b4da4be0af6221515b47e1 to your computer and use it in GitHub Desktop.
Save alanyoshida/2e5d8c5682b4da4be0af6221515b47e1 to your computer and use it in GitHub Desktop.
Exemplo de Currying com JS
var filmes = [
{ name: 'Matrix', genero: 'acao'}
,{ name: 'Mad Max', genero: 'acao'}
,{ name: 'Interestelar', genero: 'ficcao cientifica'}
,{ name: 'A origem', genero: 'ficcao cientifica'}
,{ name: 'Seven', genero: 'policial'}
];
var hasGenero = function(genero){
return function(obj){
return obj.genero === genero;
}
};
var FilmesAcao = filmes.filter(hasGenero('acao'));
console.log('Filmes de acao: \n', FilmesAcao);
console.log('\n');
var FilmesFiccao = filmes.filter(hasGenero('ficcao cientifica'));
console.log('Filmes de ficcao cientifica: \n',FilmesFiccao);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment