Sollicitatievraag

Sollicitatiegesprek voor de functie Front End Developer

-Oakland, CA

LinkedIn

// Given var endorsements = [ { skill: 'css', user: 'Bill' }, { skill: 'javascript', user: 'Chad' }, { skill: 'javascript', user: 'Bill' }, { skill: 'css', user: 'Sue' }, { skill: 'javascript', user: 'Sue' }, { skill: 'html', user: 'Sue' } ]; getSkills = (endorsements) => { // Result // [ // { skill: 'javascript', user: ['Chad', 'Bill', 'Sue'], count: 3 }, // { skill: 'css', user: ['Sue', 'Bill'], count: 2 }, // { skill: 'html', user: ['Sue'], count: 1 } // ]; } see this image: http://i.imgur.com/UIeB3n4.png

Antwoord

Antwoorden op sollicitatievragen

4 antwoorden

1

let endorsements = [ { skill: 'css', user: 'Bill' }, { skill: 'javascript', user: 'Chad' }, { skill: 'javascript', user: 'Bill' }, { skill: 'css', user: 'Sue' }, { skill: 'javascript', user: 'Sue' }, { skill: 'html', user: 'Sue' }, ]; let x = endorsements.reduce((acc, { skill, user }) => { if (skill in acc) { acc[skill] = { user: [...acc[skill]['user'], user], count: acc[skill]['count'] + 1, skill: skill, }; } else { acc[skill] = { user: [user], count: 1, skill: skill, }; } return acc; }, {}); console.log(Object.values(x));

Anoniem op

0

getSkills = endorsements => { const skillMap = {}; // assumption - each object has all the properties, nothing is missing endorsements.forEach((item, index) => { const { skill, user } = item; if (!skillMap[skill]) { skillMap[skill] = {}; skillMap[skill]["user"] = []; // skillMap[skill]["user"].push(user); skillMap[skill]["count"] = 0; } skillMap[skill]["user"].push(user); skillMap[skill]["count"] += 1; // } }); return Object.keys(skillMap).map(key => [ { skill: key, ...skillMap[key] } ]); };

Anoniem op

0

let array=[]; let user_Array=[]; let value_exist=false; for(let i=0,len=endorsements.length;i

Anoniem op

0

const getSkills = (endorsements) => { const endorsementsMap = endorsements.reduce((accum, curr) => { const { skill, user } = curr; if (accum.has(skill)) { accum.set(skill, [...accum.get(skill), user]); } else { accum.set(skill, [user]); } return accum; }, new Map()); let result = []; for (let [skill, user] of endorsementsMap.entries()) { result.push({ skill, user, count: user.length || 0 }); } return result; };

Anonymous op

Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.