Skip to content

Instantly share code, notes, and snippets.

@franvarney
Created June 14, 2017 05:23
Show Gist options
  • Save franvarney/096e50661f31f00397aebed0c3d950f8 to your computer and use it in GitHub Desktop.
Save franvarney/096e50661f31f00397aebed0c3d950f8 to your computer and use it in GitHub Desktop.
// 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