Skip to content

Instantly share code, notes, and snippets.

@ClementParis016
Last active February 1, 2017 15:00
Show Gist options
  • Save ClementParis016/efb82537fb2a88f8213a9434070dee81 to your computer and use it in GitHub Desktop.
Save ClementParis016/efb82537fb2a88f8213a9434070dee81 to your computer and use it in GitHub Desktop.
Map an object with Object.keys and Array.prototype.reduce
const weekDays = {
monday: "Monday",
tuesday: "Tuesday",
wednesday: "Wednesday",
thursday: "Thursday",
friday: "Friday"
};
const mappedWeekDays = Object.keys(weekDays).reduce((mapper, day) => {
mapper[day] = {
morning: true,
afternoon: false
};
return mapper;
}, {});
console.log(mappedWeekDays);
// => { monday: { morning: true, afternoon: false }, tuesday: { morning: true, afternoon: false }, ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment