Skip to content

Instantly share code, notes, and snippets.

@TimurM
Created July 15, 2015 16:46
Show Gist options
  • Save TimurM/a474ac9db93bd623ba5a to your computer and use it in GitHub Desktop.
Save TimurM/a474ac9db93bd623ba5a to your computer and use it in GitHub Desktop.
queryMap = {
name: 'Timur',
last_name: 'Meyster',
email: '[email protected]'
}
var turnMapToArray = function(queryMap) {
var queryResult = []
for (var key in queryMap) {
queryResult.push([key, queryMap[key]])
}
return queryResult;
}
var joinArrayStrings = function(arrayStr) {
return arrayStr.reduce(function(joinedArray, arrayItem) {
return joinedArray.concat(arrayItem.join("="));
}, [])
}
var convertToQueryStr = function(arrayKeyValueStr) {
return arrayKeyValueStr.join("&");
}
console.log(convertToQueryStr(joinArrayStrings(turnMapToArray(queryMap))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment