Skip to content

Instantly share code, notes, and snippets.

@FBosler
Last active August 18, 2020 16:20
Show Gist options
  • Save FBosler/23c0bd8b9e25130e4632c3be25dab614 to your computer and use it in GitHub Desktop.
Save FBosler/23c0bd8b9e25130e4632c3be25dab614 to your computer and use it in GitHub Desktop.
IN:
const employees = [
{
"name": "John Don't",
"performance": "medium",
"salary": 10000
},
{
"name": "Jane Does",
"performance": "high",
"salary": 9000
}
]
const adjust_salary = (employee) => {
const brackets = {
"high": 1.2,
"medium": 1.03,
"low": 1
}
const factor = brackets[employee.performance]
const current_salary = employee.salary
return {
"name" : employee.name,
"performance": employee.performance,
"salary": current_salary * factor
}
}
employees.map(employee => adjust_salary(employee))
OUT:
[
{
"name":"John Don't",
"performance":"medium",
"salary":10300.0
},
{
"name":"Jane Does",
"performance":"high",
"salary":10800.0
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment