Skip to content

Commit 062ca1f

Browse files
committed
feat: Strings Palindrome
1 parent 2d50357 commit 062ca1f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Strings/palindrome.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
var isPalindrome = function (text){
3+
text = text.split('');
4+
let index = 0;
5+
let palindrom = true;
6+
7+
const pTeks = text.length;
8+
9+
let i = 0;
10+
while((i < pTeks/2) && (palindrom === true)) {
11+
if(text[index] == text[pTeks-1]) {
12+
index++;
13+
pTeks--;
14+
} else {
15+
palindrom=false;
16+
}
17+
18+
i++;
19+
}
20+
21+
return palindrom;
22+
}
23+
24+
// test
25+
var cases = "ada apa dengan kakak kakak lari sejak malam ada ada saja";
26+
27+
cases.split(" ").map(function(res, i){
28+
console.log(res+" : isPalindrom? "+isPalindrome(res));
29+
});

0 commit comments

Comments
 (0)