you could use a property of the object to keep function result.
This is called Memorization.
Today I have a chance to utilize this skill.
Please read codes below first:
getOffOrigin has to use some logic to compare the two arguments and return a string.
The result wouldn't change if the arguments are the same.
Therefore, to avoid calling the function many times, the result could be stored in the function itself.
If we only have one arguments we could use it as the key to cache directly.
But we have multiple arguments in this case, we then use stringilized JSON to be the key.
Hence we don't need to do the same thing every time we enter this function if the arguments are used before.