Skip to content
Advertisement

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 thiniking maybe I am not writing it as Hacker Rank

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 array .reduce with async/await

Seem to be having some issues incorporating async/await with .reduce(), like so: The data object is logged before the this.store completes… I know you can utilise Promise.all with async loops, but does that apply to .reduce()? Answer The problem is that your accumulator values are promises – they’re return values of async functions. To get sequential evaluation (and all but

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 values. If no initialValue is provided

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 concise ES6 implementation with that

Advertisement