The input is a simple array of objects(contacts)
Input :
[
{ name: "Mohan", phone: xxxxxx },
{ name: "Ramanujan", phone: xxxxxx },
{ name: "Rabindranath", phone: xxxxxx },
{ name: "Satyajit", phone: xxxxxx },
{ name: "Subhash", phone: xxxxxx },
{ name: "Bahadur", phone: xxxxxx }
];
Output I would like to have:
[
{ title: "B", data: [{ name: "Bahadur", phone: xxxxxx }] },
{ title: "M", data: [{ name: "Mohan", phone: xxxxxx }] },
{
title: "R",
data: [
{ name: "Ramanujan", phone: xxxxxx },
{ name: "Rabindranath", phone: xxxxxx }
]
},
{
title: "S",
data: [
{ name: "Satyajit", phone: xxxxxx },
{ name: "Subhash", phone: xxxxxx }
]
}
];
I would appreciate the time you put in. Thank you.
Even the pseudo-code will do fine.