-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblme65.js
More file actions
30 lines (19 loc) · 800 Bytes
/
problme65.js
File metadata and controls
30 lines (19 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* : Create a function that takes a string as input and returns the reversed version of the string without using the built-in reverse() method. */
/* Example Input: "hello world" Example Output: "dlrow olleh" */
/* ----------------------------
Solution One:
------------------------------- */
function textReverser(text){
let reverseText = '';
for(let i = text.length - 1; i >= 0; i--){
const letter = text[i];
reverseText = reverseText + letter;
}
return reverseText;
}
console.log(textReverser("hello world"));
/* ----------------------------
Solution Two:
------------------------------- */
const stringReverser = text => text.split('').reduce((previous, present) => present + previous, '' );
console.log(stringReverser("hello world"));