Skip to content
Exercise · Strings · lesson 10 of 12

Exercise: which word comes first

Write a function function isBefore(a, b) that returns true if the word a comes before the word b in alphabetical order, and false otherwise. Capital and small letters count as the same.

  • isBefore("apple", "Banana") → true
  • isBefore("Zebra", "apple") → false
  • isBefore("app", "Apple") → true

Constraints: a and b have 1 to 20 Latin letters; a word that matches the start of another comes before it, and for words that are equal ignoring case the result is false.

Do not add extra imports unless the task says so explicitly.

before.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way