This is my approach.
function intersection(stringArray) { const parseArray = (array) => [...new Set(array.split(',').map(item => item.trim()))]; const [a, b] = stringArray; const aParsed = parseArray(a); const bParsed = parseArray(b); const mergedData = [...aParsed, ...bParsed]; const counter = {}; mergedData.forEach(item => { counter[item] = (counter[item] || 0) + 1; }); return Object.entries(counter).filter(item => item[1] > 1).map(item => item[0]).join(','); }
Nice custom parseArray function!! And I like that use of Object.entries().
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is my approach.
Nice custom parseArray function!! And I like that use of Object.entries().