Skip to content

Commit 78ab564

Browse files
committed
feat: Strings Palindrome
1 parent 2d50357 commit 78ab564

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Strings/palindrome.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
var isPalindrome = function (text){
3+
text = text.split('');
4+
index=0;
5+
palindrom=true;
6+
7+
pTeks=text.length;
8+
9+
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)