🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of SergiiVlasiuk

SergiiVlasiuk's solution

to Pangram in the Scala Track

Published at Aug 17 2019 · 0 comments
Test suite

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

The Scala exercises assume an SBT project scheme. The exercise solution source should be placed within the exercise directory/src/main/scala. The exercise unit tests can be found within the exercise directory/src/test/scala.

To run the tests simply run the command sbt test in the exercise directory.

For more detailed info about the Scala track see the help page.


Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


import org.scalatest.{Matchers, FunSuite}

/** @version 1.4.0 */
class PangramTest extends FunSuite with Matchers {

  test("sentence empty") {
    Pangrams.isPangram("") should be (false)

  test("recognizes a perfect lower case pangram") {
    Pangrams.isPangram("abcdefghijklmnopqrstuvwxyz") should be (true)

  test("pangram with only lower case") {
    Pangrams.isPangram("the quick brown fox jumps over the lazy dog") should be (true)

  test("missing character 'x'") {
    Pangrams.isPangram("a quick movement of the enemy will jeopardize five gunboats") should be (false)

  test("another missing character, e.g. 'h'") {
    Pangrams.isPangram("five boxing wizards jump quickly at it") should be (false)

  test("pangram with underscores") {
    Pangrams.isPangram("the_quick_brown_fox_jumps_over_the_lazy_dog") should be (true)

  test("pangram with numbers") {
    Pangrams.isPangram("the 1 quick brown fox jumps over the 2 lazy dogs") should be (true)

  test("missing letters replaced by numbers") {
    Pangrams.isPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog") should be (false)

  test("pangram with mixed case and punctuation") {
    Pangrams.isPangram(""""Five quacking Zephyrs jolt my wax bed."""") should be (true)

  test("upper and lower case versions of the same character should not be counted separately") {
    Pangrams.isPangram("the quick brown fox jumps over with lazy FX") should be (false)
object Pangrams {
  def isPangram(input: String): Boolean = {
    val lowerCase = input.toLowerCase
    ('a' to 'z').forall {

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?