Skip to content

Instantly share code, notes, and snippets.

View KenCorbettJr's full-sized avatar

Ken Corbett KenCorbettJr

  • Inventory Shield
  • Charlotte, NC
View GitHub Profile
/**
* An implementation for Quicksort. Doesn't
* perform as well as the native Array.sort
* and also runs the risk of a stack overflow
*
* Tests with:
*
* var array = [];
* for(var i = 0; i < 20; i++) {
* array.push(Math.round(Math.random() * 100));
@KenCorbettJr
KenCorbettJr / JavaScript: underscore conditionals
Created March 12, 2012 18:04 — forked from brianarn/underscore_conditionals.js
JavaScript: Underscore conditional
// A means of using underscore.js to do templates with conditionals
// Inside of underscore's template, it returns a function that uses
// 'with' on a variable named obj, and you can touch into that using
// inline JS and <% %> wrappers
// A template with conditional display of last names:
var good = _.template("Hello: <%= name %> <% if (obj.lastname) { %> <%= lastname %> <% } %>");
// A template that tries to do that, but fails:
var bad = _.template("Hello: <%= name %> <% if (lastname) { %> <%= lastname %> <% } %>");