From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Challenge: Convert array

Challenge: Convert array - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Challenge: Convert array

(upbeat techno music) - [Instructor] To close out this course, we're going to do a few challenges that require you to use functional concepts to solve problems. And our first challenge is this. Let's say that an election has happened in our home town, and we have an array of the votes, which are just strings with the person's name. Now first of all please note that none of these names is in any way meant as a references to any candidate who's currently running in any election. So what we want to do is write a function that takes this array of election votes, and produces an object like this, with the candidates' names, and the number of votes that they had in the array. Now this might not seem too hard, but there are a few catches. The first catch is that you're not allowed to hard code any of these names into your function. For all practical purposes, assume that you don't even know what names are in this election votes array. We want to write a function that in theory could work…

Contents