fork download
  1. <?php
  2.  
  3. function unique($palavra){
  4. $p = str_split($palavra);
  5. return implode(array_map(function ($c) use ($p) {
  6. return ($c > 0 && $p[$c] == $p[$c - 1] ? '': $p[$c]);
  7. }, array_keys($p)));
  8. }
  9.  
  10.  
  11. echo unique("Banana") . "\n"; // Banana
  12. echo unique("Arara") . "\n"; // Arara
  13. echo unique("assassinos") . "\n"; // asasinos
  14. echo unique("Marreco") . "\n"; // Mareco
  15. echo unique("Elllizabettth") . "\n"; // Elizabeth
  16. echo unique("FooBaaar") . "\n"; // FoBar
  17. echo unique("Woow") . "\n"; // Wow
  18. echo unique("baazz") . "\n"; // baz
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
Banana
Arara
asasinos
Mareco
Elizabeth
FoBar
Wow
baz