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 / quiz app links
Created November 23, 2020 06:18
Links to quiz app
@jessegilbride
jessegilbride / CSS-boilerplate-2020
Created November 11, 2020 15:07
My CSS boilerplate (2020)
:root {
--variableName: value;
}
header {}
main {}
section {
margin: 0 auto; /* center the content */
@jessegilbride
jessegilbride / HTML5-boilerplate-2020
Last active November 11, 2020 14:53
My current (2020) HTML boilerplate
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1">
<meta name="description" content="">
<title>Page Title</title>
<!-- CSS reset -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
@jessegilbride
jessegilbride / zipCodeValidation.js
Created September 15, 2016 21:33
Form validation for zip code*, using jQuery.validator.js https://jqueryvalidation.org/ * US Postal Code, 5 or 9 digits
$("form").validate({
rules: {
Zip: {zipCodeValidation: true} // hook in custom zip code validation
}
});
$.validator.addMethod("zipCodeValidation", function() {
var zipCode = $('input#zip').val();
return (/(^\d{5}$)|(^\d{5}-\d{4}$)/).test(zipCode); // returns boolean
}, "Please enter a valid US zip code (use a hyphen if 9 digits).");
@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]) {
function order() {
var food;
function waiter(order) {
chef(order);
return food;
}
function chef(order) {
if (order === 'pasta') {
food = ['pasta', 'gravy', 'seasoning'];
cook();
@jessegilbride
jessegilbride / footer-copyright-updater.js
Created November 13, 2015 00:01
Auto-update footer copyright year
@jessegilbride
jessegilbride / sublimetext-keybind-overrides.txt
Last active November 2, 2016 15:49
My Sublime Text (2) user preferences
[
// Causes tabs to switch like a browser...
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
// Returns home/end keys to their original usage...
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
// Related to above, allows for highlighting with shift+home/end...