// Please write a function to reverse the following nested input value into output value
// Input:
let inputValue = {
hired: {
be: {
to: {
deserve: 'I'
}
}
}
};
// Output:
let outputValue = {
I: {
deserve: {
to: {
be: 'hired'
}
}
}
};
The unit test contains 5 scenerios:
☑️ Reverse nested objects with single key in every layer
☑️ Empty object at the innermost layer will be ignore
☑️ Return empty object when inputValue is an empty object
☑️ Throw error when the innermost layer is an array
☑️ Throw error when inputValue is an array
Please follow these steps to see the test results:
-
Download
git clone https://github.com/Kaikai8888/reverse-nested-object.git
-
Install Jest
npm install
-
Run test
npm run test