题解 | #接口#
接口
https://www.nowcoder.com/practice/8f91b606181746558e8a398e513d1078
let data = [ {name: 'nowcoder1'}, {name: 'nowcoder2'} ], l=data.length; const _api = string => { // 补全代码 const s = string.split("?"); if(s[0] == 'get') { return data; } else if(s[0] == "update") { //[xxx,yyy] [n=x,t=y] [[n,x],[t,y]] [x,y] const [from,to] = s[1].split("&").map(str => str.split("=").pop()); for(let i = 0; i < l;i++) { if(data[i].name == from) { data[i].name = to; } } } }