Avatar of 4d47

4d47's solution

to Isogram in the PHP Track

Published at Jul 13 2018 · 0 comments
Test suite

Determine if a word or phrase is an isogram.

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

  • lumberjacks
  • background
  • downstream
  • six-year-old

The word isograms, however, is not an isogram, because the s repeats.

Running the tests

  1. Go to the root of your PHP exercise directory, which is <EXERCISM_WORKSPACE>/php. To find the Exercism workspace run

     % exercism debug | grep Workspace
  2. Get PHPUnit if you don't have it already.

     % wget --no-check-certificate https://phar.phpunit.de/phpunit.phar
     % chmod +x phpunit.phar
  3. Execute the tests:

     % ./phpunit.phar isogram/isogram_test.php


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

Submitting Incomplete Solutions

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



require "isogram.php";

class IsogramTest extends PHPUnit\Framework\TestCase
    public function testIsogram()

    public function testNotIsogram()

    public function testMediumLongIsogram()

    public function testCaseInsensitive()

    public function testIsogramWithHyphen()

    public function testIgnoresMultipleHyphens()

    public function testWorksWithGermanLetters()

    public function testIgnoresSpaces()
        $this->assertFalse(isIsogram('the quick brown fox'));

    public function testIgnoresSpaces2()
        $this->assertTrue(isIsogram('Emily Jung Schwartzkopf'));

    public function testDuplicateAccentedLetters()

function isIsogram($str, $enc = 'UTF-8')
    preg_match_all('/\pL/u', mb_strtoupper($str), $results);
    $letter_counts = array_count_values($results[0]);
    return max($letter_counts) === 1;

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?