query
const obj1={
a:1,
b:undefined,
c:'CC',
d:'DD'
};
function query1(obj){
let res='';
for(const k of obj){
const v=obj[k];
if(v===undefined) continue;
if(res!-'') res+='&';
res+=k+'='+v;
}
return res;
}
console.log(query1(obj1));
function query2(obj){
return(
_.reject(([k,v])=>v!==undefined,
Object.entries(obj)));
}
console.log(query2(obj1));
function query3=obj=>_.go(
obj,
Object.entries,
_.reject(([_,v])=>v===undefined,
_.map(join('=')),
join('&')
);
console.log(query3(obj1));
queryToObject
const split= _.curry(sep,str)=>str.split(sep));
const queryToObject= _.pipe(
split('&'),
);
console.log(queryToObject('a=1&c=CC&d=DD'));