Skip to content

Instantly share code, notes, and snippets.

@kigiri
Created March 12, 2018 22:06
Show Gist options
  • Save kigiri/3fef39fc627e72620c155e02e2e85c3f to your computer and use it in GitHub Desktop.
Save kigiri/3fef39fc627e72620c155e02e2e85c3f to your computer and use it in GitHub Desktop.
const wilder = {
firstName: 'Clément',
lastName: 'Denis',
age: 30,
isExperienced: true,
}
const showWilder = (w) => {
const firstName = w.firstName.toLowerCase()
const lastName = w.lastName.toUpperCase()
return `${firstName} ${lastName} ${w.age}`
}
const wilderSaruman = {
firstName: 'Saruman',
lastName: 'Pat',
age: 89,
isExperienced: true,
}
const wilderList = [
wilder,
wilderSaruman,
{
firstName: 'Pépito',
lastName: 'Rodrigez',
age: 12,
isExperienced: false,
},
]
const showAllWilders = list => list.forEach(showWilder)
const wildersAverageAge = list => {
let total = 0
list.forEach(w => total = total + w.age)
return total / list.length
}
const over30 = list => {
const filteredList = []
list.forEach(w => {
if (w.age > 30) {
filteredList.push(w)
}
})
return filteredList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment