Middle+
Implement a function foo that takes an array and returns an object where the keys are the elements of the array and the values are all 0.
sobes.tech AI
Answer from AI
javascript function foo(arr) { return arr.reduce((acc, item) => { acc[item] = 0; return acc; }, {}); }
// Example usage: const input = ['a', 'b', 'c']; const result = foo(input); console.log(result); // { a: 0, b: 0, c: 0 }