const portfolio = [
{ name: 'Mark', stock: 'FB' },
{ name: 'Steve', stock: 'AAPL' },
{ name: 'Tim', stock: 'AAPL' },
{ name: 'Steve', stock: 'MSFT' },
{ name: 'Bill', stock: 'MSFT' },
{ name: 'Bill', stock: 'AAPL' },
];
// Output
const shareholder = [
{ stock: 'AAPL', name: ['Steve', 'Bill', 'Tim'], count: 3 },
{ stock: 'MSFT', name: ['Steve', 'Bill'], count: 2 },
{ stock: 'FB', name: ['Mark'], count: 1 },
];
if I create one function which take input array as param and this will return output array in jS