All Questions
40 questions
-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) {
...
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 ...
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 ...
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 = ...
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 ...
-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,...
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 = ...
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 ...
-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] ...
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 '_'(...
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}
],
...
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,...
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 ...
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 ...
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 ...