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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -