Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Isabella
Isabella

Posted on

     

.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 togetherjoin('') 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 apalindrome. 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.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Let`s discuss JavaScript basics and Codewars problems
  • Location
    Romania
  • Joined

More fromIsabella

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp