Skip to content

Instantly share code, notes, and snippets.

@evaporei
Created September 26, 2017 02:35
Show Gist options
  • Save evaporei/c68e10650d374c7cb1178bc3348e9a2d to your computer and use it in GitHub Desktop.
Save evaporei/c68e10650d374c7cb1178bc3348e9a2d to your computer and use it in GitHub Desktop.
Ramda functional exercise 3 - Get the names of the 3 youngest users
const R = require('ramda')
const json = {
users: [
{id: 3, name: "Thad", age: 36},
{id: 5, name: "Lucian", age: 23},
{id: 2, name: "Justine", age: 29},
{id: 4, name: "Katie", age: 26},
{id: 0, name: "Jerold", age: 52},
{id: 1, name: "Nona", age: 33}
]
}
// exercise 3: get the names of the 3 youngest users
const usersSortedByAge = R.sortBy(R.prop('age'))(json.users)
const getNamesOfYongestUsers = n => R.pipe(
R.sortBy(R.prop('age')),
R.take(n),
R.map(R.prop('name'))
)(json.users)
console.log(getNamesOfYongestUsers(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment