SHARE
TWEET

Untitled

a guest Mar 24th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top