This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -18,7 +18,16 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const reverseString = (str) => {};
|
||||
const reverseString = (str) => {
|
||||
if (str.length <= 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// console.log('str.slice(1): ', str.slice(1));
|
||||
// iwie kapier ich das mit den rückgabewarten von rekursiven funktionen noch net wirklich
|
||||
return reverseString(str.slice(1)) + str[0];
|
||||
// return ... <-- ("lo") + "l" <--- ("llo") + "e" <-- ("ello") + "h"
|
||||
};
|
||||
|
||||
// Test cases
|
||||
console.log(reverseString('hello')); // => "olleh"
|
||||
|
||||
Reference in New Issue
Block a user