Skip to content

Tag: reduce

A very big sum – Hacker Rank

I am trying to solve “A very big sum” challenge on Hacker Rank: https://www.hackerrank.com/challenges/a-very-big-sum/problem In there I have to sum all the numbers in the array given so I came up with two solutions: First solution Second Solution But none of them work and I don´t know why, I am th…

Using reduce() to find min and max values?

I have this code for a class where I’m supposed to use the reduce() method to find the min and max values in an array. However, we are required to use only a single call to reduce. The return array should be of size 2, but I know that the reduce() method always returns an array of size 1. I’m

JavaScript – examples of reduce() function

I’m looking at this example of use of reduce() function. Could you give show me some other examples of using reduce() – I’m not sure I fully follow how it works. Thank you Answer What reduces does is take an initialValue, a function with 2 essential parameters (can take more) and a list of v…

Javascript Object to querystring using reduce

I’m having trouble to apply a reduce to an Object to get it in a querystring format. I want this: So far, the close I have got is this: which gives me: Is there an easier way to achieve this without have to prepend the initialValue and remove the & later? EDIT: This question is old and today we can

Javascript reduce() on Object

There is nice Array method reduce() to get one value from the Array. Example: What is the best way to achieve the same with objects? I’d like to do this: However, Object does not seem to have any reduce() method implemented. Answer What you actually want in this case are the Object.values. Here is a con…