forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.js
More file actions
31 lines (26 loc) · 718 Bytes
/
palindrome.js
File metadata and controls
31 lines (26 loc) · 718 Bytes
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
/*
Classical palindrome js version.
"A palindrome is a word, number, phrase, or other sequence of
characters which reads the same backward as forward, such as madam, racecar."
https://en.wikipedia.org/wiki/Palindrome
*/
/**
* Returns if the string is palindrome or not
* case sensitive
* @param {string} string. Required
* @returns {boolean}
*/
function isPalindrome(string) {
if((string === string.split("").reverse().join(""))){
return true;
}else{
return false;
}
}
function isPalindromeTest() {
const stringList = ['', 'hi', 'ANA', 'racecar'];
for (string of stringList) {
console.log(isPalindrome(string), 'Ups! %s is not palindrome :/', string);
}
}
isPalindromeTest();