Created
December 28, 2017 01:57
-
-
Save jlarocque/dceaca03d8fe4acf131e5e66225aea70 to your computer and use it in GitHub Desktop.
Palindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Palindrome Challenge - JavaScript JumpStart | |
Have the function **palindrome(str)** take the str parameter being passed, and return the boolean `true` if the argument is a palindrome (meaning that the string is the same forward as it is backward). Otherwise, return the boolean `false`. | |
Punctuation and numbers will not be part of the string. | |
- INPUT: palindrome("racecar"); | |
- OUTPUT: true | |
- INPUT: palindrome("animal"); | |
- OUTPUT: false | |
*/ | |
// Write Code Below | |
function palindrome(str){ | |
var newStr = ''; | |
for (var i = str.length -1; i >=0 ; i--){ | |
newStr += str[i]; | |
} | |
if (newStr === str){ | |
return true; | |
} else{ | |
return false; | |
} | |
} | |
describe('palindrome', function(){ | |
it('palindrome is a function', function(){ | |
expect(typeof palindrome).toEqual('function'); | |
}); | |
it('palindrome returns a boolean value', function(){ | |
expect(typeof palindrome("codepen")).toEqual('boolean'); | |
}); | |
it('returns true if the argument is a palindrome', function(){ | |
expect(palindrome('racecar')).toEqual(true); | |
expect(palindrome('madam')).toEqual(true); | |
}); | |
it('returns false if the argument is not a palindrome', function(){ | |
expect(palindrome('Mark Davis')).toEqual(false); | |
expect(palindrome('space jam')).toEqual(false); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment