JAVASCRIPT IN PRACTICE

Shortest code (golf)

Shortest code (golf) - solve it, but length counts. Fit within the character limit and beat the shortest-solution record. Trains conciseness and language tricks.

  • Correctness
  • Character limit
  • Concise JavaScript
Preview the first challenge →

Solving requires a free account.

Selected challenges to get started

Pick a challenge and explore the rules through a concrete example.

Easy

Max (golf)

Return the largest array element. The array is non-empty and contains finite numbers.

Preview challenge → Free account required to solve
Easy

Reverse string (Golf)

Reverse string with min chars. Reverse Unicode code points without splitting emoji surrogate pairs.

Preview challenge → Free account required to solve
Easy

Is even (Golf)

For integer n, return a boolean: true if n is even, otherwise false. Zero and negative even integers also return true.

Preview challenge → Free account required to solve

Ready for more?

Available challenges: 7.

See all challenges →

The full catalogue requires a free account.

How should you approach these challenges?

JavaScript code golf practises concision: you seek a shorter expression while preserving the required behaviour. You explore alternative uses of operators and language methods. In application code, assess those shortcuts for readability as well as character count.

First write a solution that passes the tests, then shorten it. Change one fragment at a time and check the character limit. Type-coercion shortcuts can fail for zero, empty strings or empty arrays, so rerun every case after each optimisation.

Explore an example: Max (golf) →

Read the description without logging in. Solving requires a free account.