Skip to content

feat: Strings Palindrome #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Strings/palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

var isPalindrome = function (text){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to use ES6 standards

text = text.split('');
let index = 0;
let palindrom = true;

const pTeks = text.length;

let i = 0;
while((i < pTeks/2) && (palindrom === true)) {
if(text[index] == text[pTeks-1]) {
index++;
pTeks--;
} else {
palindrom=false;
}

i++;
}

return palindrom;
}

// test
var cases = "ada apa dengan kakak kakak lari sejak malam ada ada saja";

cases.split(" ").map(function(res, i){
console.log(res+" : isPalindrom? "+isPalindrome(res));
});