Skip to content

Instantly share code, notes, and snippets.

View jessegilbride's full-sized avatar

Jesse Gilbride jessegilbride

View GitHub Profile

Stack and Queue Exercises

Palindromes

A palindrome is a word, phrase, or number that is spelled the same forward and backward. For example, “dad” is a palindrome; “A man, a plan, a canal: Panama” is a palindrome if you take out the spaces and ignore the punctuation; and 1,001 is a numeric palindrome. We can use a stack to determine whether or not a given string is a palindrome.

Write a function that takes a string of letters and returns true or false to determine whether it is palindromic. For example:

function is_palindrome(s) {
    s = s.toLowerCase().replace(/[^a-z]/g, "");
 // your code goes here

Two of the most commonly used data structures in web development are stacks and queues. The history of pages visited in a web browser and the undo operation in a text editor are examples of operations made possible using stacks. The handling of events in web browsers often uses a queue data structure.

Stack

A stack is a data structure that stores elements in a LIFO (Last In First Out) order. It's like a stack of plates in your kitchen. When a plate is added, it is pushed towards the bottom of a stack. The last plate that you stack becomes the one on the top of the stack and it is the first one that you get to use.

A stack has two basic functions:

  • push(): places data onto the top of a stack
  • pop(): removes data from the top of the stack
@jessegilbride
jessegilbride / smashingmagazine.js
Created July 18, 2016 22:09 — forked from luruke/smashingmagazine.js
Source code of the demo "Improving User Flow Through Page Transitions" on Smashing Magazine.
/*
https://www.smashingmagazine.com/2016/07/improving-user-flow-through-page-transitions/
You can copy paste this code in your console on smashingmagazine.com
in order to have cross-fade transition when change page.
*/
var cache = {};
function loadPage(url) {
if (cache[url]) {
@jessegilbride
jessegilbride / 0_reuse_code.js
Created August 25, 2014 00:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console