Skip to content

Commit fbec5a6

Browse files
committed
Add palindrome algo
1 parent bdc904f commit fbec5a6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎strings/palindrome.js‎

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

0 commit comments

Comments
 (0)