Last active
March 25, 2019 10:50
-
-
Save tomi/4cc5d42b55746eb33df58be1386e977a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { from } from "fromfrom"; | |
const users = [ | |
{ id: 1, name: "John", age: 31, score: 2244, active: true }, | |
{ id: 2, name: "Jane", age: 32, score: 2492, active: false }, | |
{ id: 3, name: "Luke", age: 33, score: 2500, active: false }, | |
… | |
{ id: 1000, name: "Mary", age: 34, score: 2290, active: true }, | |
]; | |
from(users) | |
.filter(user => user.active) | |
.pick("id", "name", "score") | |
.sortByDescending(user => user.score) | |
.take(5) | |
.toArray(); | |
// End result: | |
// [ | |
// { id: 214, name: "May", score: 5622 }, | |
// { id: 353, name: "Peter", score: 5212 }, | |
// { id: 32, name: "Macy", score: 5112 }, | |
// { id: 972, name: "Laura", score: 5023 }, | |
// { id: 429, name: "Bob", score: 4900 } | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your comments! The previous version was indeed erroneous. The end result objects should only contain properties
id
,name
andscore
. It should be now fixed