Skip to content
Advertisement

Use reduce instead of nested for loops? [closed]

I’m trying to print out the multiplication table using js. Is there a cleaner way to do this than with nested for loops? I was thinking of reduce as an alternative. Any onther ideas out there? 😉

JavaScript
JavaScript

Advertisement

Answer

Yes it is possible. Since you have a nested for loop, you need two reduces: a reduce per row and a reduce for the entire table :

JavaScript

That being said, in your case you’d probably want to create an HTML table.

Snippet

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