freeCodeCamp/curriculum/challenges/spanish/08-coding-interview-prep/rosetta-code/accumulator-factory.spanish.md

1.8 KiB
Raw Blame History

title id challengeType videoUrl localeTitle
Accumulator factory 594810f028c0303b75339ace 5 Fábrica de acumuladores

Description

Cree una función que tome un solo argumento (numérico) y devuelva otra función que sea un acumulador. La función del acumulador devuelto a su vez también toma un solo argumento numérico y devuelve la suma de todos los valores numéricos pasados hasta ese acumulador (incluido el valor inicial pasado cuando se creó el acumulador).

Reglas:

No utilice variables globales.

Insinuación:

Los cierres salvan el estado exterior.

Instructions

Tests

tests:
  - text: <code>accumulator</code> es una función.
    testString: 'assert(typeof accumulator === "function", "<code>accumulator</code> is a function.");'
  - text: <code>accumulator(0)</code> debe devolver una función.
    testString: 'assert(typeof accumulator(0) === "function", "<code>accumulator(0)</code> should return a function.");'
  - text: <code>accumulator(0)(2)</code> debe devolver un número.
    testString: 'assert(typeof accumulator(0)(2) === "number", "<code>accumulator(0)(2)</code> should return a number.");'
  - text: 'Pasar los valores 3, -4, 1.5 y 5 debe devolver 5.5.'
    testString: 'assert(testFn(5) === 5.5, "Passing in the values 3, -4, 1.5, and 5 should return 5.5.");'

Challenge Seed

function accumulator (sum) {
  // Good luck!
}

After Test

console.info('after the test');

Solution

// solution required