Files
30-seconds-of-code/snippets/flags.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

492 B

title, tags, author, cover, firstSeen
title tags author cover firstSeen
Array to flags object array,object chalarangelo glass-blowing 2022-04-12T05:00:00-04:00

Converts an array of strings into an object mapping to true.

  • Use Array.prototype.reduce() to convert the array into an object, where each array value is used as a key whose value is set to true.
const flags = arr => arr.reduce((acc, str) => ({...acc, [str]: true }), {});
flags(['red', 'green']); // { red: true, green: true }