Skip to content
Open
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
11 changes: 9 additions & 2 deletions tasks/1. Palindrome check/palindrome.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export function isPalindrome(inputString) {
// TODO: write your code here
}
//RegExp to remove unwanted characters from input string
var re = /[\W_]/g;
//turning all characters to lowercase and using RegExp to get rid of unwanted characters
var lowRegStr = inputString.toLowerCase().replace(re, '');
//spliting the string into individual characters, reversing the character positions (first character becomes last, last becoms first ect) then recombining them into a string
var reverseStr = lowRegStr.split('').reverse().join('');
//if the reverse string is equal to the intial it is a palindrome and return true, If not return false.
return reverseStr === lowRegStr;
}