← Back to challenges

Fix The Error: Array Reduce

JavaScriptHardbugsarraysstrings

Instructions

The instructor assigns Boron two tasks (regarding the use of reduce() method after lecturing in array methods).

  1. The first task is to create a function calculateSum() that takes a string and returns the sum of the ASCII values of all the characters in the string using reduce().
  2. The second task is to create a function reverseString() that reverses and returns an input string using reduce().

While solving the problem, Boron has encountered errors. Help him fix the errors.

Examples

calculateSum("lime") ➞ 423
// 108 + 105 + 109 + 101 = 423

calculateSum("a") ➞ 97
// a = 97

reverseString("hello") ➞ "olleh"

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: The Fibonacci Number