“.Reduce mdn” Respostas de código

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

sintaxe de redução em js

[1,2,3,4,5].reduce((acc, current)=>acc+current, 0)
Healthy Hamster

reduzir o método

function reduce(array, combine, start) {
  let current = start;
  for (let element of array) {
    current = combine(current, element);
  }
  return current;
}

console.log(reduce([1, 2, 3, 4], (a, b) => a + b, 0));
// → 10
Xanthous Xenomorph

.Reduce mdn

arr.reduce(callback( accumulator, currentValue[, index[, array]] )[, initialValue])
Clear Civet

reduzir o método

The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value.

The reducer function takes four arguments:
Accumulator (acc)
Current Value (cur)
Current Index (idx)
Source Array (src)

//syntax
arr.reduce(callback( accumulator, currentValue, [, index[, array]] )[, initialValue])
//example flatten an array

let flattened = [[0, 1], [2, 3], [4, 5]].reduce(
  ( accumulator, currentValue ) => accumulator.concat(currentValue),
  []
)
kepl3r

Respostas semelhantes a “.Reduce mdn”

Perguntas semelhantes a “.Reduce mdn”

Procure respostas de código populares por idioma

Procurar outros idiomas de código