Closed azl397985856 closed 3 years ago
function myFunction(ns) {
return Object.fromEntries(Object.entries(ns).reverse().map(entry => entry.reverse()))
}
const myFunction = obj => {
const res = {};
const entries = Object.entries(obj).reverse();
for (const [key, value] of entries) {
res[value] = key;
}
return res;
};
function myFunction(ns) {
const keys = Object.keys(ns);
const values = Object.values(ns);
const obj = {};
for(let i = values.length - 1; i >= 0; i--){
obj[values[i]] = keys[i];
}
return obj;
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
// Write a function that takes an object as argument // Somehow, the properties and keys of the object got mixed up // Swap the Javascript object's key with its values and return the resulting array // Tipp: although usually not relevant, mind the order of the properties in the test case outputs
test case:
你可以去 https://www.jschallenger.com/javascript-objects/swap-object-keys-values/challenge?id=5f1043abbd87ab5028fee12e 在线检查自己的答案。