I'm seeking a rationale for why Approach A is considered superior to Approach B.
Approach A:
const transformCompanyOptions = (companies: Array<{id: string, name: string}>, selectedId: string) => {
return companies.map(key => {
return {
value: key.id,
label: key.name,
checked: key.id === selectedId
}
})
};
Approach B:
const transformCompanyOptions = (companies: Array<{id: string, name: string}>, selectedId: string) => {
const ret = Object.keys(companies).map((key) => {
const newCompany = {};
newCompany['value'] = companies[key].id;
newCompany['label'] = companies[key].name;
if (companies[key].id === selectedId) {
newCompany['checked'] = true;
}
return newCompany;
});
return ret;
};
Your insights are greatly appreciated!