Question: I wrote a function that searches through the values of an object. The key is returned when its confirmed that the key matches the index
I wrote a function that searches through the values of an object. The key is returned when its confirmed that the key matches the index of the value stored in the array.
eg. 19 is in index 0 in the array, and in the object, the key for 19 is 0. Since this matches, the key is returned.
However, if the value is found in the object but the index is wrong in the array, -2 is returned. Finally, when a value is not found in the object, -1 is returned.
Here is an example object:
const exampleObject = {
0: 19,
1: 20,
2: 21,
3: 22 };
Please derive the best case and worst case run times for this algorithm and write it as a recurrence relation with step by step explanation

function getKey(array, object, value) { for (const prop in object) { if (object[prop] value && array[prop] == value ) { return prop } else if (object [prop] === value && array(prop] !== value ) { return -2 } } return -1 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
