Created
January 28, 2022 21:28
-
-
Save Sirpyerre/fae8ad7cd00d162efd1aa2508656b1cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// "internacionalization oso entertainment internacionalization oso entertainment ahho atto a2o a2o" => "i18n oso e11t internacionalization oso entertainment" | |
// "apa water a aa" | |
echo summarize("internacionalization oso entertainment"); | |
function summarize(string $input) | |
{ | |
$words = explode(" ", $input); | |
$sizeTmp = count($words); | |
$resume = ""; | |
$output = []; | |
$duplicates = []; | |
for ($i=0;$i<$sizeTmp; $i++){ | |
$duplicates[] = $words[$i]; | |
$duplicates[$words[$i]] = 1; | |
$duplicates["internacionalization"] = 1; | |
if(isset($duplicates["internacionalization"])) { | |
$duplicates["internacionalization"]++; | |
} | |
$str = $words[$i]; | |
$size = strlen($str); | |
if ($size > 3) { | |
$resume = $str[0] . ($size-2) . $str[$size-1]; | |
$output[$i] = $resume; | |
} else { | |
$output[$i] = $str; | |
} | |
} | |
return implode(" ",$output); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment