Last active
December 21, 2015 04:09
-
-
Save pomahtuk/6247686 to your computer and use it in GitHub Desktop.
1. Напишите функцию разбора query-строки в набор параметров.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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