Skip to content

Instantly share code, notes, and snippets.

@jlarocque
Created December 28, 2017 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlarocque/dceaca03d8fe4acf131e5e66225aea70 to your computer and use it in GitHub Desktop.
Save jlarocque/dceaca03d8fe4acf131e5e66225aea70 to your computer and use it in GitHub Desktop.
Palindrome
<script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script>
/*
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