My task is to write a function that swaps the value of an element with the value at the same location within the second object.
{placeOne:10,placeTwo:20},{ten:"firstPlace",twenty:"secondPlace"}
{placeOne:"firstPlace",placeTwo:"secondPlace"},{ten:10,twenty:20} // should equal this
I wanted to try an approach that pushed the objects value into an array, then loop through the object and set each position to the position within the array.
But I had trouble looping through the object and the array at the same time so I could not solve it that way.
Heres what I have so far.
function swapObj(obj1,obj2){
let obj1Arr = [];
let obj2Arr = [];
for(var i in obj1) {
obj1Arr.push(obj1[i]);
}
for(var k in obj2) {
obj2Arr.push(obj2[k])
}
swapObj({placeOne:10,placeTwo:20,placeThree:30,},
{ten:"firstPlace",twenty:"secondPlace",thirty:"thirdPlace"}
)