Skip to content

Instantly share code, notes, and snippets.

View ThreeHammers3_bollocks
var param = stream.getData() //This is bollocks
View ThreeHammers3_streams
-------click-------click---------click------->
**********************************************
----------------"a=1&a=2&b=3"---------------->
**********************************************
------------"a=1&a=2&b=3"-------------------->
observablePerPair
View ThreeHammers3_rx-solution
var Rx = require('rx');
var
observablePerPair = function(string) {
return Rx.Observable.from(string.split('&'));
},
splitEqual = function(pairString) {
return pairString.split('=');
},
key = function (pair) {
View ThreeHammers2_groupBy
{
a: [
['a', '1'],
['a', '2']
],
b: [
['b', '3']
]
}
View ThreeHammers2_ramda_version
var R = require('ramda');
var
//[[key, value]] -> {key: [[key, value]]}
groupByKey = R.groupBy(R.head),
//{'':a, 'b':b} -> {'b':b}
rejectEmptyKeys = R.pickBy(function(value, key) {return key !== '';}),
//[[key, value]] -> [value | undefined]
View ThreeHammers1_ImperativeSolution
function objectizeUrlSearch (paramString) {
var
pairStrings = paramString.split('&'),
pairs = [],
result = {},
i;
for (i = 0; i < pairStrings.length; i++) {
pairs.push(pairStrings[i].split('='));
}
View ThreeHammers1_TestSuite
var UrlSearch = require("./url-search");
describe("objectizeUrlSearch", function () {
it("should convert search string to search object", function() {
var
urlSearch = "a=1&a=2&b=3",
searchObject = {
"a": ["1","2"],
"b": "3"
};
expect(UrlSearch.objectizeUrlSearch(urlSearch))