Skip to main content

All Questions

Filter by
Sorted by
Tagged with
-3 votes
2 answers
71 views

Array items length is not working inside the function

I want to filter an item and return only the longest word with out special characters (#$%^&*) but the length inside reduce function doesn't work. //that what I tried function LongestWord(sen) { ...
ahmed kamel's user avatar
1 vote
2 answers
228 views

Refactor: How to use .reduce with an external function?

hope that you're doing well. I've a question related to the .reduce function. I'm refactoring an elder code and, in order to fulfill the DRY principle, I'd like to know how to create a function that ...
MarcoPavez's user avatar
0 votes
0 answers
16 views

How can I access array in function composition created by reduce? [duplicate]

So I have this function that that takes in an array of functions where each function edits the array and it will compose a master function from the array of functions. However, I keep getting this ...
Kai Suzuki's user avatar
0 votes
2 answers
32 views

How do you concatenate several arrays into one?

const sumAll = function (min, max) { const allSums = []; const initialValue = 0; for (let i = min; i <= max; i++) { allSums.push([i]); } console.log(allSums); // let sumTotal = ...
Moomins's user avatar
  • 23
0 votes
1 answer
152 views

Javascript : Using .reduce and passing in a function to add strings

I'm trying to use the .reduce method passing in a function and an initial value 'Stack' but I've been getting undefined. I added a console.log in the reduce method to see what may be going wrong, and ...
Enochy's user avatar
  • 11
-4 votes
1 answer
37 views

I would like to ask why is 0 part of the argument?

I get the entire logic of the reduce method, and rest parameter, however I really don't get the importance of 0. Thank you very much in advance! const sum = (...args) => { return args.reduce((a,...
Meri's user avatar
  • 9
0 votes
1 answer
305 views

Confusing on Reduce and Arrow function [duplicate]

I am now looking at the following post Javascript Algorithm Attempting to Implement Call Back Function. I can understand the other parts but particularly confuse at the following code. const sum = ...
echo's user avatar
  • 35
0 votes
3 answers
73 views

How to define a function in javascript reduce function?

I have an object student, it has property id, name, groupName. allStudents is the array of student objects, I want to turn it to an id to student map, but for each student, I want to generate a new ...
spspli's user avatar
  • 3,338
-2 votes
3 answers
2k views

reduce method in javascript gets undefined

How do I use the reduce method in solving this problem? I keep getting undefined. I am trying to only print out the numbers that are bigger while going through the loop. so for example [ 1,4,2,9,1,12] ...
SherrieChenautl's user avatar
0 votes
3 answers
726 views

how to split a string by chunks of 2 characters using reduce

I am trying to use reduce to get the following output: solution('abcdef') // should return ['ab', 'cd', 'ef'] if the length of the string is odd we should convert it into even and add a '_'(...
elisa's user avatar
  • 229
0 votes
2 answers
57 views

Wrong calculation with reduce

Can someone explain why this equals 052 and not 7? I simply dont get it. products: [ {id: 1, name: 'Baju', Hours: 2}, {id: 2, name: 'Celena', Hours: 5} ], ...
egx's user avatar
  • 409
0 votes
0 answers
75 views

Accumulator is not working as expected -Reducer function in Javascript

I dont understand how the accoumulator is working here in this simple reduce function. i understand accumulator is that after each iteration the accumulator value will be passed to the next iteration,...
umair's user avatar
  • 93
0 votes
1 answer
58 views

What is the flow of execution with this compose function passed into Javascripts reduce?

I just want to know how reduce works in the case of code below(which was provided by a stackoverflow user in my previous question, i'm asking this question as his code snippet led to me having more ...
SuthanS's user avatar
  • 53
1 vote
1 answer
153 views

How does the reduce function work when a function is returned? Would also like to know more about compose and composition

The following code is written in a functional manner. There is a user object which is going to make a purchase. The process is as follow: an item is added to the cart, tax is added, the item is bought ...
SuthanS's user avatar
  • 53
0 votes
3 answers
60 views

JavaScript - implementing map function with reduce, error when passing function as argument

I am trying to implement a map function in javascript using reduce. function newMap(inputArr, fn) { return inputArr.reduce((mapItem, elem) => mapItem = (fn(elem)), []) } function ...
Greg Iven's user avatar
  • 183

15 30 50 per page