AI 구현
This commit is contained in:
+22
-1
@@ -284,6 +284,14 @@ class Util extends \utilphp\util
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function convertArrayToSetLike($arr){
|
||||
$result = [];
|
||||
foreach($arr as $datum){
|
||||
$result[$datum] = $datum;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function convertPairArrayToDict($arr){
|
||||
$result = [];
|
||||
foreach($arr as [$key, $val]){
|
||||
@@ -308,7 +316,7 @@ class Util extends \utilphp\util
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function squeezeFromArray(array $dict, string $key){
|
||||
public static function squeezeFromArray(array $dict, $key){
|
||||
$result = [];
|
||||
foreach($dict as $dictKey=>$value){
|
||||
$result[$dictKey] = $value[$key];
|
||||
@@ -586,6 +594,19 @@ class Util extends \utilphp\util
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getKeyOfMaxValue(array $array){
|
||||
$max = null;
|
||||
$result = null;
|
||||
foreach ($array as $key => $value) {
|
||||
if ($max === null || $value > $max) {
|
||||
$result = $key;
|
||||
$max = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 배열의 아무거나 고름. Python의 random.choice()
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user