“Reduza JavaScript” Respostas de código

Reduza JavaScript

let array = [36, 25, 6, 15];
 
array.reduce((acc, curr) => acc + curr, 0)
// 36 + 25 + 6 + 15 = 82
Rick Oburu

JavaScript reduz

var array = [36, 25, 6, 15];

array.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0); // 36 + 25 + 6 + 15 = 82
TC5550

.DUCE JavaScript

reduce function sample solution
Tuffour Boateng

Reduza em JavaScript

// Reduce in javascript advance
// output: { '22': 2, '24': 2, '26': 1 }
const user = [
  {name:"Abhishek",age:24},
  {name:"Dhruval",age:22},
  {name:"Anish",age:26},
  {name:"Aakash",age:22},
  {name:"Darshil",age:24},
]
const newUser = user.reduce((acc,cur)=>{
  if(acc[cur.age]){
    acc[cur.age] = acc[cur.age] +1 
  }
  else{
    acc[cur.age] = 1 
  }
  return acc;
},{})

console.log(newUser)
Abhishek

Reduza JavaScript

//note idx and sourceArray are optional
const sum = array.reduce((accumulator, element[, idx[, sourceArray]]) => {
	//arbitrary example of why idx might be needed
	return accumulator + idx * 2 + element 
}, 0);
slgotting

Reduza JavaScript

let fil = res.map(x=>Object.keys(x).filter(x=>x!='process' && x!='relay_type')
  .reduce((a,b)=>{
    a[b] = x[b]
    return a
  },{})).map(x=>Object.assign(x,{total:'wew'}))
Maeron Reyes

Respostas semelhantes a “Reduza JavaScript”

Perguntas semelhantes a “Reduza JavaScript”

Mais respostas relacionadas para “Reduza JavaScript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código