“.Reduce MDN” Réponses codées

JavaScript réduit

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

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

.reduce javascript

reduce function sample solution
Tuffour Boateng

syntaxe de réduire en js

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

réduire la méthode

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

réduire la méthode

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

Réponses similaires à “.Reduce MDN”

Questions similaires à “.Reduce MDN”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code