Skip to content

Instantly share code, notes, and snippets.

@khaled0fares
Last active July 31, 2016 12:47
Show Gist options
  • Save khaled0fares/4589d687f8a97356f71f82332d4b4f28 to your computer and use it in GitHub Desktop.
Save khaled0fares/4589d687f8a97356f71f82332d4b4f28 to your computer and use it in GitHub Desktop.
Palindrome using stack.
let stack = require("https://gist.github.com/khaled0fares/4ffe7a9db1c4c71b1e361c2c636f0c71");// Link to the stack gist, for calirfication only.
let isPalindrome = function(txt){
let len = txt.length,
stack = new Stack(len),
reversed = "",
i = 0;
while(!stack.full()){
stack.push(txt[i]);
++i
}
while(!stack.empty()){
reversed += stack.peek(); // Get top element in the stack.
stack.pop();
}
return txt === reversed;
}
console.log(isPalindrome("1001"));// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment