Ternary Operator confuse

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 {

You will need a return statement in each of your cases.

Also, I’m not sure that you pulled apart the ternary correctly.

is it possible to put your code on the solution, please?

Nope, for two reasons

  1. I don’t have enough of the original code to work with here
  2. I’d rather help you modify your code than do it for you
1 Like

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…