<?php function countUniqueCharacters(string $str): int { static $cache = []; if (key_exists($str, $cache)) { return $cache[$str]; } echo PHP_EOL . "*** doing the work ***"; return $cache[$str] = count( array_filter( count_chars($str, 1), fn($count) => $count === 1 ) ); } $tests = ['one', 'two', 'three', 'one', 'two']; foreach ($tests as $test) { echo PHP_EOL . "$test : " . countUniqueCharacters($test); }
You have javascript disabled. You will not be able to edit any code.