I have a function, rangeInclusive
, which accepts two args:
function rangeInclusive(start, end) {
...
}
In order to calculate the start
and end
values I have another function called getValidYearRange
:
getValidYearRange() {
let validRange = [];
if (myCondition === 'foo') {
validRange = [this.calculateValidYear1(), this.calculateValidYear2()];
} else {
validRange = [1900, 2017];
}
return validRange;
}
As you can see I have a condition set that determines whether the range is my hardcoded values, or calls another two functions to get more info.
However I get the following problem, rangeInclusive
seems to get the arguments as an array and undefined, e.g:
start = [1900, 2017], end = undefined
rather than:
start = 1900, end = 2017
I cannot change rangeInclusive
at all as it's used throughout the project.
How can I return two values for start
and end
without calling functions twice?