Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function solve(arr) {
  2. let palindromeResult = []
  3. for (let word of arr) {
  4. let currentWord = word.split(' ').filter(x => x !== ' ').join('')
  5. let reversedWord = currentWord.split('').reverse().join('')
  6. if (currentWord === reversedWord) {
  7. palindromeResult.push(currentWord)
  8. }
  9.  
  10. }
  11. if (palindromeResult.length > 0) {
  12. console.log(palindromeResult.join(', '))
  13. } else {
  14. console.log(`No palindromes found`)
  15. }
  16.  
  17.  
  18. }
  19.  
  20. solve(['stella won wallets',
  21. 'not a palindrome']
  22. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement