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

  if(n < 0) {
    return 0;
  } else if(n === 0) {
    return 1;
  } else if(memo[n]) {
    return memo[n];
  } else {
    ways = countWays(n - 1, memo) + countWays(n - 2, memo) + countWays(n - 3, memo);
  }

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

This version is more succinct
Order matters, 3 steps: 1-2 and 2-1 are two different ways

@param n
@param memo
@returns {*}