Skip to content

Instantly share code, notes, and snippets.

@danwoods
danwoods / knapsack.js
Last active April 19, 2022 13:57
Knapsack algorithm in JavaScript
//Knapsack algorithm
//==================
// wikipedia: [Knapsack (0/1)](http://en.wikipedia.org/wiki/Knapsack_problem#0.2F1_Knapsack_Problem)
// Given a set `[{weight:Number, benefit:Number}]` and a capacity,
// find the maximum value possible while keeping the weight below
// or equal to the capacity
// **params**:
// `capacity` : Number,
// `items` : [{w:Number, b:Number}]
// **returns**:
@dimaxweb
dimaxweb / XmlIslandsParse
Created May 4, 2013 10:03
Xml parsing without ActiveX in Internet Explorer.Works only in IE!!!
funtion parseWitoutActiveX(str)
var doc= null;
var xmlIsland = document.createElement('xml');
if(xmlIsland){
xmlIsland.setAttribute('id','xmlActiveXGetRid');
xmlIsland.innerHTML = str;
document.body.appendChild(xmlIsland);
var doc = xmlIsland.XMLDocument;
document.body.removeChild(xmlIsland);
return doc;