Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var text = "I remember the group ABBA, that brought lots of wow in the music world."
- text = text.replace(/\W/g, ' ');
- var array = text.split(' ');
- console.log(palindromsExtraction(array));
- function palindromsExtraction(arr) {
- var strToReturn = [];
- for (var word in arr) {
- arr[word] = arr[word].trim();
- var isPalindrome = true;
- for (var i = 0; i < arr[word].length / 2; i++) {
- if (arr[word][i] !== arr[word][arr[word].length - 1 - i]) {
- isPalindrome = false;
- break;
- }
- }
- if (isPalindrome && arr[word].length>1)strToReturn.push(arr[word]);
- }
- return strToReturn;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement