Skip to content
Advertisement

Transform an Array into an Object using .reduce()

I am trying to study Array.reduce. And I was given the following task:

Input data:

JavaScript

And I need to get this data in the output

JavaScript

I tried to write some code, but I have no idea how to do it correctly. How can I solve this problem?

Code:

JavaScript

Advertisement

Answer

Corrected the logic

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement