Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // --- Directions
  2. // Given a string, return true if the string is a palindrome
  3. // or false if it is not. Palindromes are strings that
  4. // form the same word if it is reversed. *Do* include spaces
  5. // and punctuation in determining if the string is a palindrome.
  6. // --- Examples:
  7. // palindrome("abba") === true
  8. // palindrome("abcdefg") === false
  9.  
  10. // Method 1
  11. function palindrome(str) {
  12. const reversed = str.split('').reverse().join('');
  13. return str === reversed;
  14. }
  15.  
  16. // Method 2
  17. function palindrome(str) {
  18. return str.split('').every((char, i) => {
  19. return char === str[str.length - i - 1];
  20. });
  21. }
  22.  
  23. module.exports = palindrome;
Add Comment
Please, Sign In to add comment