Furthest Point From Origin

EasyStringCounting

Solution

export function furthestDistanceFromOrigin(moves: string): number {
  let left = 0;
  let right = 0;
  let both = 0;
  for (const move of moves) {
    if (move === 'L') {
      left += 1;
    } else if (move === 'R') {
      right += 1;
    } else {
      both += 1;
    }
  }
 
  return Math.abs(left - right) + both;
}