Skip to content

Instantly share code, notes, and snippets.

@pomahtuk
Last active December 21, 2015 04:09
Show Gist options
  • Save pomahtuk/6247686 to your computer and use it in GitHub Desktop.
Save pomahtuk/6247686 to your computer and use it in GitHub Desktop.
1. Напишите функцию разбора query-строки в набор параметров.
var query_to_object = function(url) {
var param, params, query, result, _i, _len;
if (url == null) {
url = 'http://moto1.englearn.org/index.php?route=product/product==&path=59&product_id=50';
}
query = url.split('?')[1];
result = {};
if (query != null) {
params = query.split('&');
for (_i = 0, _len = params.length; _i < _len; _i++) {
param = params[_i];
param = param.split('=');
result[param.splice(0, 1)] = param.join('=');
}
}
return result;
};
query_to_object = (url = 'http://moto1.englearn.org/index.php?route=product/product==&path=59&product_id=50' ) ->
query = url.split('?')[1]
result = {}
if query?
params = query.split('&')
for param in params
param = param.split('=')
result[param.splice(0,1)] = param.join('=')
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment