Number of Segments in a String

EasyString

Solution

export function countSegments(s: string): number {
  const matched = s.match(/([^ ]+)/g);
  return matched ? matched.length : 0;
}