return elem
? !Array.isArray(elem)
? steamrollArray(arr, [elem, ...flatArr])
: steamrollArray(arr.concat(elem), flatArr)
: flatArr;
I want to use regular if-else cases instead of using ternary operators so how can I revert that block code from ternary operator to regular if-else this block code?
My code as below :
if (steamrollArray(arr, [elem, ...flatArr])) {
return elem;
} else {
steamrollArray(arr.concat(elem), flatArr);
}
} else {
flatArr;
}
You will need a return statement in each of your cases.
Also, I’m not sure that you pulled apart the ternary correctly.
cihatsaman:
return elem /* condition1 */
? !Array.isArray(elem) /* result if condition1 is true, which is another if */
? steamrollArray(arr, [elem, ...flatArr]) /* result if condition2 is true and condition1 is true */
: steamrollArray(arr.concat(elem), flatArr) /* result if condition2 is false but condition1 is true */
: flatArr; /* result if condition1 is false */
is it possible to put your code on the solution, please?
To get you started, I’ll simplify it a bit:
return elem
? firstOption
: secondOption;
With if-else, this would be
if (elem) {
return firstOption
} else {
return secondOption
}
1 Like
Thank you for clear explaining I understood what I am missing…
system
Closed
September 11, 2021, 10:07am
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.