MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / ReverseStringIterative

Function ReverseStringIterative

String/ReverseString.js:4–16  ·  view source on GitHub ↗

* A short example showing how to reverse a string.

(string)

Source from the content-addressed store, hash-verified

2 * A short example showing how to reverse a string.
3 */
4function ReverseStringIterative(string) {
5 if (typeof string !== 'string') {
6 throw new TypeError('The given value is not a string')
7 }
8 let reversedString = ''
9 let index
10
11 for (index = string.length - 1; index >= 0; index--) {
12 reversedString += string[index]
13 }
14
15 return reversedString
16}
17
18/**
19 *

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected