Created
July 30, 2017 21:50
-
-
Save HoangPV/99f3b7e46d823af367d7f91d123a746d to your computer and use it in GitHub Desktop.
return the max words of sentences, which is from a text
This file contains 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 | |
/** | |
* return the max words of sentences, which is from a text | |
* | |
* @param $s | |
* @return mixed | |
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com> | |
*/ | |
function solution($s) | |
{ | |
$delimiters = ['.', '?', '!']; | |
$ready = str_replace($delimiters, $delimiters[0], $s); | |
$launch = explode($delimiters[0], $ready); | |
$arr_words_count = []; | |
foreach ($launch as $index => $sen) { | |
$ps = explode(" ", $sen); | |
$non_letters = []; | |
foreach ($ps as $p) { | |
if (is_numeric($p) || $p === '') { | |
$non_letters[] = $p; | |
} | |
} | |
$letters = array_diff($ps, $non_letters); | |
$arr_words_count[] = count($letters); | |
} | |
return max($arr_words_count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment