-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardRow.php
More file actions
42 lines (33 loc) · 827 Bytes
/
KeyboardRow.php
File metadata and controls
42 lines (33 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* @param String[] $words
* @return String[]
*/
function findWords($words) {
$palabras = [];
$row[0] = str_split('qwertyuiop');
$row[1] = str_split('asdfghjkl');
$row[2] = str_split('zxcvbnm');
foreach ($words as $word) {
$tempWord = strtolower($word);
$rowIndex = -1;
$flag = true;
for ($i = 0; $i < 3; $i++) {
if (in_array($tempWord[0], $row[$i])) {
$rowIndex = $i;
break;
}
}
$wordArray = str_split($tempWord);
foreach ($wordArray as $letter) {
if (!in_array($letter, $row[$rowIndex])) {
$flag = false;
break;
}
}
if ($flag) {
$palabras[] = $word;
}
}
return $palabras;
}