I'm working with an object of objects. I need to keep it as an object because I'm work with an API that requires me to keep it that way (that part is not debatable).
This is an example schema of my object:
const obj = {
1: { name: 'Initial Step 1', stepNumber: 1 },
2: { name: 'Initial Step 2', stepNumber: 2 },
3: { name: 'Initial Step 3', stepNumber: 3 },
}
I need to implemented a moveUp
function that will take the stepNumber
and obj
as the first and second parameters respectively.
This moveUp
function basically needs to swap one inner object with the object above it. Eg. moveUp(2, obj)
should change the obj
as follows:
{
1: { name: 'Initial Step 2', stepNumber: 1 },
2: { name: 'Initial Step 1', stepNumber: 2 },
3: { name: 'Initial Step 3', stepNumber: 3 },
}
The stepNumber
will never be equal to 1
, thanks to the interface I've built.
How should I implement my moveUp
function?
I basically need this:
export const moveUp = (stepNumber, obj) => {
// I need help here
};
Thanks!