Created
June 14, 2017 05:23
-
-
Save franvarney/096e50661f31f00397aebed0c3d950f8 to your computer and use it in GitHub Desktop.
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
// Francesca | |
// REVERSE A STRING | |
const assert = require('assert'); | |
function reverse(str) { | |
let output = ''; | |
for (let i = 0; i < str.length; ++i) { | |
output += str[str.length - 1 - i]; | |
} | |
return output; | |
} | |
assert.equal(reverse("ABCD"), "DCBA"); | |
// STRING IS PALINDROME | |
function isPalindrome(str) { | |
for (let i = 0; i < Math.floor(str.length / 2); ++i) { | |
if (str[i] !== str[str.length - 1 -i]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
console.log(isPalindrome("m")); // not sure if this should be a palindrome, can make edits accordingly | |
console.log(isPalindrome("mom")); | |
console.log(isPalindrome("meem")); | |
console.log(isPalindrome("nope")); | |
console.log(isPalindrome("nop")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment