Pergunta de entrevista da empresa AppsFlyer

write a function that, given a URL of an http get request, return to client a key:value structure of the parameters in the URL.

Respostas da entrevista

Sigiloso

13 de mai. de 2019

// random example app.get('/expressions/:id', (req, res, next) => { console.log(req.params); ---> this is the answer const foundExpression = getElementById(req.params.id, expressions); if (foundExpression) { res.send(foundExpression); } else { res.status(404).send(); } });

Sigiloso

15 de out. de 2019

// assuming the URL is valid function myUrlParser(url){ const result = {}; let urlParts = url.split('?'); if ( urlParts[1] === undefined ) { return 'No parameters in the given URL.'; } const urlPairs = urlParts[1].split('&'); urlPairs.forEach(pair => { const parts = pair.split('='); result[parts[0]] = parts[1]; }); return result; }