Skip to content
Advertisement

Tag: reduce

How to .reduce() an array that contains functions?

Lets say we have an array of functions Is there a way to funcArray.reduce() and have all three functions apply on the string using reduce? Answer Compose is an HOC, which means it takes function and returns function. Trick is to decide when to execute the functions. Here is a sample function that will work like redux’s compose

Use reduce instead of nested for loops? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 months ago. Improve this question I’m trying to print out the multiplication table using js. Is there a cleaner way to do this than with nested

How to proper use reduce() javascript/typescript

I try to solve task below with reduce() and actually the result is ok. But I don’t know how to use acc in reduce() instead of acc1 or indexMax. How to apply typescript to this task. The task: Find first word with max repeated letter count. For example rrrtygggg and ttbvfddjklyyyaseqq – the winner is rrrtygggg. If sequence has no

How to write this function with forEach?

I am trying to group the people by their age and as you can see, my code works with the reduce method. I managed to get this working but now I want to do the same with forEach method. Here’s my code: Answer Reduce accepts initial value that you update each iteration and return. So if you wish to use

Reduce nested array maximum values to a single array

I am trying to find a way to reduce the max values of specific positions/indexes within nested arrays into a single array. Given: const myArr = [[105,87,171],[113,192,87],[113,87,87],[113,87,87]] Expected return value: [113,192,171] Actual return value: [113,87,87] Using the following code, I’m getting the above return value. Why am I only getting the max value for the first position, and not the

Looping through and reducing nested array

I can’t seem to get my head around the array.reduce() function. I’ve got the following array: and I’m trying to get a result like below. I’m not sure how to go about multiplying the ingredient amounts with the item quantities: I’ve tried following the structure that was given here but the arrow function is throwing me off. Any sort of

Advertisement