javascript - Using reduce fnt instead of map -


any advise on how can refactor function using reduce, should not use map here?

try this:

function serializeparams (object) {     return object.keys(object)         .reduce((query, key) =>             array.isarray(object[key])                 ? query.concat(object[key].map(value => `${key}=${encodeuricomponent(value)}`))                 : query.concat(`${key}=${encodeuricomponent(object[key])}`)         , [])         .join('&'); } 

or without template strings:

function serializeparams (object) {     return object.keys(object)         .reduce((query, key) =>             array.isarray(object[key])                 ? query.concat(object[key].map(value => key + '=' + encodeuricomponent(value)))                 : query.concat(key + '=' + encodeuricomponent(object[key]))         , [])         .join('&'); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -