Skip to content

Instantly share code, notes, and snippets.

View trafficinc's full-sized avatar

Ron trafficinc

  • Greater Philadelphia
View GitHub Profile
@trafficinc
trafficinc / linkedList.js
Last active April 14, 2018 01:33
JavaScript LinkedList
function LinkedList(value) {
this.head = null;
this.length = 0;
this.addToHead(value);
}
LinkedList.prototype.addToHead = function(value) {
var newNode = { value: value } ;
newNode.next = this.head;
this.head = newNode;
@trafficinc
trafficinc / queue.js
Last active May 21, 2018 05:31
JavaScript Queue
function Queue() {
this.dataStore = [];
this.enqueue = enqueue;
this.dequeue = dequeue;
this.front = front;
this.back = back;
this.toString = toString;
this.empty = empty;
}
@trafficinc
trafficinc / stack.js
Created April 13, 2018 21:29
JavaScript Stack Class
function Stack() {
this.dataStore = [];
this.top = 0;
this.push = push;
this.pop = pop;
this.peek = peek;
this.clear = clear;
this.length = length;
}
@trafficinc
trafficinc / SimpleEventBus.js
Last active May 13, 2019 19:27
Simple JS Event Bus
var EventBusClass = {};
EventBusClass = function() {
this.listeners = {};
};
EventBusClass.prototype = {
addEventListener: function(type, callback, scope) {
var args = [];
var numOfArgs = arguments.length;
for(var i=0; i<numOfArgs; i++){
args.push(arguments[i]);
@trafficinc
trafficinc / tree.js
Last active December 21, 2020 16:03
JS Tree data structure
var Node = function (name) {
this.children = [];
this.name = name;
}
Node.prototype = {
add: function (child) {
this.children.push(child);
},
@trafficinc
trafficinc / switchjs.js
Last active February 27, 2018 14:15
Alternative to switch statement, JavaScript
== requires jquery ====
==== html ======
<div id="show"></div>
===== js ======
function switchcase(cases,defaultCase,key) {
if (cases.hasOwnProperty(key)) {
return cases[key];
} else {
@trafficinc
trafficinc / JS_object_PHP.php
Last active December 30, 2017 16:42
Create JS like object in PHP for quick object creation
<?php
// Creating a JS 'like' Object in PHP
class JSObject {
function __construct($members = array()) {
foreach ($members as $name => $value) {
$this->$name = $value;
}
}
function __call($name, $args) {
<?php
$unsorted = array(43,21,2,1,9,24,2,99,23,8,7,114,92,5);
function quick_sort($array)
{
// find array size
$length = count($array);
// base case test, if array of length 0 then just return array to caller
//HashTable
function HashTable() {
this.table = new Array(137);
this.betterHash = betterHash;
this.showDistro = showDistro;
this.put = put;
//this.get = get;
}
function put(data) {
var pos = this.betterHash(data);
// LinkedList
function Node(element) {
this.element = element;
this.next = null;
}
function LList() {
this.head = new Node("head");
this.find = find;
this.insert = insert;