This commit is contained in:
Philippe Torrel
2026-09-23 10:47:07 +02:00
parent b16dd8458d
commit 082a9bd7b3
11 changed files with 209 additions and 18 deletions
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -18,7 +18,26 @@
<script>
'use strict';
const reverseString = (str) => {};
// const recurse = (str, nr) => {
// if (nr < 0) {
// return '';
// }
// return str.charAt(nr) + recurse(str, nr - 1);
// };
// const reverseString = (str) => {
// return recurse(str, str.length - 1);
// };
function reverseString(str) {
// Base case: if the string has only one character, return it
if (str.length <= 1) {
return str;
}
// Recursive case: return the last character of the string and call the function with the rest of the string
return reverseString(str.slice(1)) + str[0];
}
// Test cases
console.log(reverseString('hello')); // => "olleh"