Skip to content

Instantly share code, notes, and snippets.

@iurii-kyrylenko
Created February 28, 2019 12:34
Show Gist options
  • Save iurii-kyrylenko/6436470e71578a2f3c1f0d70637d916d to your computer and use it in GitHub Desktop.
Save iurii-kyrylenko/6436470e71578a2f3c1f0d70637d916d to your computer and use it in GitHub Desktop.
Array to map
function flatten(arr) {
return [].concat(...arr);
}
function combine(keys, values) {
return keys.reduce((acc, key, i) =>
({ ...acc, [key]: values[i] || null }), {}
);
}
const processedDates = [
[1, 2],
// [3, 4],
[5, 6]
];
const keys = [
"freeMonthStart", "freeMonthEnd",
"freeMonth2Start", "freeMonth2End",
"freeMonth3Strat", "freeMonth3End"
];
const dates = flatten(processedDates);
result = combine(keys, dates);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment