Check if All A's Appears Before All B's

EasyString

Solution

export function checkString(s: string): boolean {
  const lastAIndex = s.lastIndexOf('a');
  const firstBIndex = s.indexOf('b');
  if (lastAIndex === -1 || firstBIndex === -1) {
    return true;
  }
  return lastAIndex < firstBIndex;
}