1.9 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.9 KiB
		
	
	
	
	
	
	
	
title, id, challengeType, forumTopicId
| title | id | challengeType | forumTopicId | 
|---|---|---|---|
| Accumulator factory | 594810f028c0303b75339ace | 5 | 302222 | 
Description
Instructions
Tests
tests:
  - text: <code>accumulator</code> is a function.
    testString: assert(typeof accumulator === 'function');
  - text: <code>accumulator(0)</code> should return a function.
    testString: assert(typeof accumulator(0) === 'function');
  - text: <code>accumulator(0)(2)</code> should return a number.
    testString: assert(typeof accumulator(0)(2) === 'number');
  - text: Passing in the values 3, -4, 1.5, and 5 should return 5.5.
    testString: assert(testFn(5) === 5.5);
Challenge Seed
function accumulator(sum) {
  // Good luck!
}
After Test
const testFn = typeof accumulator(3) === 'function' && accumulator(3);
if (testFn) {
  testFn(-4);
  testFn(1.5);
}
Solution
function accumulator(sum) {
  return function(n) {
    return sum += n;
  };
}