题解 | #参数解析器#
参数解析器
https://www.nowcoder.com/practice/9a4cca8c0779438a8be39d45d0370597
1. 时间复杂度O(n)
2. split3次 ? & =
3. 结果用reduce聚合
const _getParams = (url) => { // 补全代码 const i = url.lastIndexOf('?'); const queryStr = i > -1 ? url.slice(i + 1) : ''; return queryStr.split('&').reduce((tmp, str) => { let [k, v] = str.split('='); tmp[k] = v; return tmp; }, {}); }