* A short example showing how to reverse a string.
(string)
| 2 | * A short example showing how to reverse a string. |
| 3 | */ |
| 4 | function 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 | * |