-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseString.js
More file actions
36 lines (30 loc) · 1.05 KB
/
Copy pathreverseString.js
File metadata and controls
36 lines (30 loc) · 1.05 KB
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
31
32
33
34
35
36
function _reverseString(string, index) {
if (index === 0) {
return string[0];
}
return string[index] + _reverseString(string, index - 1);
}
function reverseString(string) {
const reverse = _reverseString(string, string.length - 1);
return reverse;
}
function getMark(expectation, actualResult) {
return expectation === actualResult ? '✅' : '❌';
}
function makeMessage(strig, expectation, actualResult) {
const context = "String: '" + strig;
const expectationSegment = " Expected output: " + ' "' + expectation + '"';
const resultSegment = "\tActual Result: " + ' "' + actualResult + '"';
const message = context + expectationSegment + resultSegment;
return message;
}
function testPalidrome(string, expectation) {
const actualResult = reverseString(string);
const mark = getMark(expectation, actualResult)
const message = makeMessage(string, expectation, actualResult)
console.log(mark, message);
}
testPalidrome("Aman", "namA");
testPalidrome("malayalam", "malayalam");
testPalidrome("one", "eno");
testPalidrome("two", "owt");