function countWays2(n, memo = []) {
  let ways = 0;

  if(memo[n]) {
    return memo[n];
  }

  if(n === 0) {
    return 1;
  }

  if(n - 1 >= 0) {
    ways += memo[n - 1] || countWays(n - 1, memo);
  }

  if(n - 2 >= 0) {
    ways += memo[n-2] || countWays(n - 2, memo);
  }

  if(n - 3 >= 0) {
    ways += memo[n-3] || countWays(n - 3, memo);
  }

  memo[n] = ways;
  return ways;
}
O(n)

Order matters, 3 steps: 1-2 and 2-1 are two different ways

@param n
@param memo
@returns {*}