Skip to content
Advertisement

How can I use map operator with for loop?

I have a function that returns a list of the total counts. I want to use the map but don’t know how I can use it.

Here is my function:

JavaScript

I want to use this with the map.

Advertisement

Answer

I don’t think it’s neccessary.

you are just constantly adding terms, so it’s just a sum and it doesn’t require to use the map() function, you could use the builtin sum() function, and a generator:

JavaScript

as @Lecdi said in the comments.

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