capitalize method

String capitalize()

Capitalizes the first letter of the string and lowercases the rest.

Returns the same string if it's empty.

Example: 'hello' → 'Hello'

Implementation

String capitalize() {
  if (isEmpty) return this;
  return this[0].toUpperCase() + substring(1).toLowerCase();
}