Skip to content
Advertisement

Tag: reduce

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

4th argument in reduce

Here is the function: The fourth argument to reduce is the array that we’re iterating over. I can log it and I get the correct result (10) see above. But when I try to use it and assign it to a variable I get an error(see above). Could someone please shed some light? Answer From Mozilla’s page, the fourth parameter

Advertisement