“.Reduce mdn” Código de respuesta

JavaScript Reduce

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

Sintaxis de reducir en js

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

Reducir el 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

Reducir el 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

Respuestas similares a “.Reduce mdn”

Preguntas similares a “.Reduce mdn”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código