Spędziłem trochę nad tym zadaniem ale żadnym sposobem nie mogę go rozwiązać. To co tam powypisywałem to tylko jedna z prób. Jak to najprościej zrobić?
function pluraliseKeys(obj) {
/*
In this function you will be provided with an object. That object is storing information on keys.
E.g. {
name: 'Tom',
job: ['writing katas', 'marking'],
favouriteShop: [
"Paul's Donkey University",
"Shaq's Taxidermy Shack",
"Sam's Pet Shop"
]
};
In some cases, however, the keys have been very badly named. Good naming convention tells us that the keys containing arrays should be named as plurals.
This function should return a **new object** that is a copy of the input but with any keys that contain arrays pluralised (an 's' added to the end.)
E.g. {
name: 'Tom',
jobs: ['writing katas', 'marking'],
favouriteShops: [
"Paul's Donkey University",
"Shaq's Taxidermy Shack",
"Sam's Pet Shop"
]
}
*/
let objNew = {...obj};
for ( let key in objNew ) {
if ( Array.isArray(objNew[key]) ) {
objNew[objNew[key] + 's'] = objNew[objNew[key]];
delete objNew[objNew[key]];
}
}
return objNew;
}