Skip to content

Instantly share code, notes, and snippets.

var _ = require('underscore');
function sortByWeight (arr, weightMap) {
arr.sort(function (e1, e2) {
var w1 = weightMap[e1];
var w2 = weightMap[e2];
if (_.isNumber(w1) && _.isNumber(w2)) {
return w1 - w2;
} else {
return 0;
(function() {
this.tmpl3 = function tmpl(str, data) {
var value = "var out = ''; out+=" + "'" +
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^%]*%>)/g,"\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/<%=(.+?)%>/g, "'; out += $1; out += '")
.split("<%").join("';")
@xuyang2
xuyang2 / comb.coffee
Last active August 29, 2015 13:57
Combination generator ported from Java
'use strict'
_ = require 'underscore'
# CombinationGenerator ported from Java.
# The algorithm is described by Kenneth H. Rosen, Discrete Mathematics and
# Its Applications, 2nd edition (NY: McGraw-Hill, 1991), pp. 284-286.
#
# Simple usage:
# combinations(["a", "b", "c", "d", "e"], 3)