Skip to content

Instantly share code, notes, and snippets.

@mcsf
Last active Apr 8, 2019
Embed
What would you like to do?
var isPopular = ( post ) => post.popularity > 9000;
var topPosts = map( getPosts(), compose(
partial( takeWhile, isPopular ),
partial( sortBy, 'popularity' ) );
// versus
var topPosts = [];
var posts = getPosts();
posts = sortBy( 'popularity', posts );
forEach( posts, function( post ) {
// only keep popular posts
if ( post.popularity > 9000 ) {
topPosts.push( post );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment