Skip to content

Instantly share code, notes, and snippets.

@callmehiphop
Last active August 29, 2015 14:03
Show Gist options
  • Save callmehiphop/fc5b250fdd48b9578d53 to your computer and use it in GitHub Desktop.
Save callmehiphop/fc5b250fdd48b9578d53 to your computer and use it in GitHub Desktop.
Super awesome functions!
// http://www.codewars.com/kata/539a0e4d85e3425cb0000a88/
function add (n) {
var next = add.bind(n += this | 0);
next.valueOf = function () {
return n;
};
return next;
}
var wat = add(1)(2)(3); // => 6
var wat2 = add(2)(3)(7)(29)(1)(5); // => 37
// http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/
var uri = 'http://your.domain/product.aspx?category=4&product_id=2140&query=lcd+tv';
var queryString = {};
uri.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { queryString[$1] = $3; }
);
console.log('ID: ' + queryString['product_id']); // ID: 2140
console.log('Name: ' + queryString['product_name']); // Name: undefined
console.log('Category: ' + queryString['category']); // Category: 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment