DEV Community

Isabella
Isabella

Posted on

1

.reverse() | .split('') | .join('') and palindrome in JS Explained

1.Create a function that takes string.
Print the reverse of that string to the console.

let unoReverse = str => console.log(str.split('').reverse().join(''))

// .split(') takes the string and it returns it into an array
//once we have the array, reverse() **can reverse each
// in this case we
split('')** in individual letters ; .reverse() can take those individual letters and it can reverse them
//Once we reversed our array, we joined back together join('') to get back a string, otherwise we will still be dealing with an array and we want our string back.
// reverse() doesnt need quotes "" because when theyve made the reverse method they didn`t needed to take in an argument to do the reversing.

2.Create a function that takes in a string.
Alert if the string is a palindrome or not.
const palindromeCheck = str => alert(str === str.split('').reverse().join(''))
palindromeCheck('racecar')

//We are going to take in a string and see if it equals the same as that reversed. So if the str(string) equals the str reversed, we know that we have a palindrome. In this case will alert 'true'.

In simple terms, when the numbers, strings, or characters are reversed that return the same result as the original numbers or characters, it is called a Palindrome.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay