akt/akt-testing-fun

使用单元测试和PHPUnit的乐趣

维护者

详细信息

gitlab.com/exotec/akt_testing_fun

问题

安装: 3

依赖项: 0

建议者: 0

安全: 0

类型:typo3-cms-extension

dev-master 2020-08-16 16:27 UTC

This package is not auto-updated.

Last update: 2022-01-03 21:41:17 UTC


README

1. 设置“喜欢”按钮标签

你可能已经从Facebook和其他页面上了解“喜欢”系统。人们可以“喜欢”博客文章、图片或其他项目。我们希望创建应显示在这样一个项目旁边的文本。

在控制器中完成此功能

TestingFunController::likes()

该函数必须接受一个包含喜欢一个项目的 peoples 名称的输入数组。它必须返回如图例所示的显示文本

likes [] // must be "no one likes this"
likes ["Peter"] // must be "Peter likes this"
likes ["Jacob", "Alex"] // must be "Jacob and Alex like this"
likes ["Max", "John", "Mark"] // must be "Max, John and Mark like this"
likes ["Alex", "Jacob", "Mark", "Max"] // must be "Alex, Jacob and 2 others like this"

2. 在数组中找到唯一值

有一个包含一些数字的数组。除了一个数字外,所有数字都相同。保证数组包含超过3个数字。试着找到它!

findUniq([ 1, 1, 1, 2, 1, 1 ]) === 2
findUniq([ 0, 0, 0.55, 0, 0 ]) === 0.55

在控制器中完成此功能

TestingFunController::findUniq()

3. 在数组中找到唯一值

在这个kata中,你的目标是实现一个差分函数,它从一个列表中减去另一个列表并返回结果。

它应该从列表a中移除所有在列表b中存在的值。

arrayDiff([1,2],[1]) == [2]

如果值在b中,则必须从另一个列表中移除其所有出现次数

arrayDiff([1,2,2,2,3],[2]) == [1,3]

在控制器中完成此功能

TestingFunController::arrayDiff()


新内容

echo alphabet_position("The sunset sets at twelve o' clock.The narwhal bacons at midnight.=-='");

function alphabet_position(string $s): string {

$alphas = range('A', 'Z');
$chars = str_split(strToUpper($s));

foreach( $chars as $k => $char) {
    if( in_array($char, $alphas)) {
        $alphaKeys[$k] = array_search ($char, $alphas) + 1;   
    }
}

if( is_array($alphaKeys) )
   return implode(' ', $alphaKeys);
return false;

}

/* function alphabet_position(string $s):string { return implode(' ', array_filter(array_map(function($x){

return array_search($x, str_split('_abcdefghijklmnopqrstuvwxyz'));}, str_split(strtolower($s)))));

} */