Skip to content

Commit

Permalink
Prevent two of the same words from repeating in characters function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexchantastic committed Jul 3, 2018
1 parent 4b46b9b commit c0fd664
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions script.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ function characters($count) {
global $lipsum;

$character_count = 0;
$words_count = 0;
$words_array = array();

while ($character_count < $count) {
$word = $lipsum->word();
$word_length = strlen($word);

$character_count += $word_length + count($words_array);
if ($word !== $words_array[$words_count - 1]) {
$character_count += $word_length + count($words_array);

array_push($words_array, $word);
array_push($words_array, $word);

$words_count = count($words_array);
}
}

$words = implode(' ', $words_array);
Expand Down

0 comments on commit c0fd664

Please sign in to comment.