Skip to content

Instantly share code, notes, and snippets.

@ccnixon
ccnixon / binary-search-tree.js
Created January 13, 2016 01:29
Binary Search Tree in JS
var BinarySearchTree = function(value){
var instance = Object.create(binaryTreeMethods);
instance.value = value
instance.left = null;
instance.right = null;
return instance;
@ccnixon
ccnixon / linked-list-reverse.js
Created January 13, 2016 01:28
Reverse a linked list in place
var reverseList = function(list){
var tempHead = list.head;
var tempTail = list.tail;
var prevNode = list.head
var currentNode = this.head.next;
while(currentNode) {
var holder = currentNode.next;
currentNode.next = prevNode;
prevNode = currentNode;
currentNode = holder
@ccnixon
ccnixon / balancedParens.js
Created December 26, 2015 17:15
Balanced Parens
function isBalanced (string) {
var queue = [];
for(var i = 0; i < string.length; i++){
if(string[i] === "("){
queue.push(string[i]);
}
if(string[i] === ")"){
queue.pop();
}
}
function makeBoard(n) {
var board = []
for (var i = 0; i < n; i++) {
board.push([])
for (var j = 0; j < n; j++) {
board[i].push(false)
}
}
board.togglePiece = function(i, j) {
this[i][j] = !this[i][j]
@ccnixon
ccnixon / eventingLibrary.js
Created December 12, 2015 17:23
Make an eventing system mix-in that adds .trigger() and .on() to any input object.
/*
Example usage:
var obj = mixEvents({ name: 'Alice', age: 30 });
obj.on('ageChange', function(){ // On takes an event name and a callback function
console.log('Age changed');
});
obj.age++;
obj.trigger('ageChange'); // This should call our callback! Should log 'age changed'.
*/
@ccnixon
ccnixon / spiralTraversal.js
Last active December 12, 2015 17:21
Write a function that accepts a 2-dimensional array (that is, an array containing many same-length arrays), and prints out every value found, but in a spiral from the upper left in to the center.
var matrix =
[ [ 1, 2, 3, 4, 5 ],
[ 6, 7, 8, 9, 10 ],
[ 11, 12, 13, 14, 15 ],
[ 16, 17, 18, 19, 20 ],
[ 21, 22, 23, 24, 25 ] ];
var spiralTraversal = function(matrix){
var results =[];
var startRowIndex = 0;
@ccnixon
ccnixon / gitflow-tutorial.sh
Created October 30, 2015 16:30 — forked from peterdeweese/gitflow-tutorial.sh
Gitflow Tutorial
set -o verbose
set -o errexit
echo '* Create and initialize a repository.'
git init gitflow-tutorial
cd gitflow-tutorial/
git flow init -d
echo '* Develop a Feature'
@ccnixon
ccnixon / app.js
Created October 22, 2015 22:40 — forked from rnkoaa/app.js
A simple angularjs with angular-ui modal form which includes validation on the client side. Thanks http://scotch.io/tutorials/javascript/angularjs-form-validation
var app = angular.module("modalFormApp", ['ui.bootstrap']);
app.controller("modalAccountFormController", ['$scope', '$modal', '$log',
function ($scope, $modal, $log) {
$scope.showForm = function () {
$scope.message = "Show Form Button Clicked";
console.log($scope.message);
var modalInstance = $modal.open({
@ccnixon
ccnixon / composeAndPipe.js
Created October 10, 2015 16:16
Compose and Pipe
var compose = function(){
//Your code here
var args = Array.prototype.slice.call(arguments);
return function(val){
return args.reduceRight(function(memo, fn){
return fn(memo);
}, val);
};
};
@ccnixon
ccnixon / bubbleSort.js
Created October 10, 2015 15:43
Bubble Sort
var bubbleSort = function(array) {
var len = array.length;
var swap = function(i,j,array){
var holder = array[i];
array[i] = array[j];
array[j] = holder;
}
for(var j = 0; j < len - 1; j++){
var swaps = false;