Coding for Scrubs: Palindromes (JS)

1. Define what a palindrome is:

2. In plain English, write what steps we have to take:

1. Split the length of the word in half
2. Create a loop to iterate through the first half of the word
3. Loop through each letter in the string starting at the end and moving backwards
4. If #1 does not equal to #2, then return false, return true

3. Create a function to test!

function isPalindrome(string) {
console.log(string)
}
console.log(isPalinedrome("hello"));#=> hello
function isPalindrome(string){
var halfString= Math.floor(string.length / 2);
}
function isPalindrome(string){
var halfString= Math.floor(string.length / 2);
for(let i = 0; i < halfString.length; i++){
console.log(string[i])
}
}
function isPalindrome(string){
var halfString = Math.floor(string.length / 2);
for(let i = 0; i < halfString.length; i++){
console.log(string[i])
console.log(string[string.length - i - 1]
}
}
function isPalindrome(string){
var halfString= Math.floor(string.length / 2);
for (var i = 0; i < halfString.length; i++){
if (string[i] !== string[string.length - i - 1]){
return false;
}
return true;
}
}
console.log(isPalindrome("tacocat")); #=> true
console.log(isPalindrome("tacodog")); #=> false
funciton isPalindrome(string{
string = string.replace(/\W/g, ''); // removes symbols
string = string.toLowerCase(); // converts to lowercase
var halfString = Math.floor(string.length / 2);
for (var i = 0; i < halfString,length; i++){
if (string[i] !== string[string.length - i - 1]){
return false;
}
return true;
}
}

Software Engineer in the making.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store