Last active
July 31, 2016 12:47
-
-
Save khaled0fares/4589d687f8a97356f71f82332d4b4f28 to your computer and use it in GitHub Desktop.
Palindrome using stack.
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
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