Last active
June 14, 2022 20:17
-
-
Save Driver86/94281a2e2245c591fe613b7ee11859fa to your computer and use it in GitHub Desktop.
Тестовые задачи
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 | |
/* | |
Нужно написать на php функцию, которая принимает строку — текст на любом языке и | |
возвращает массив из 5 наиболее часто встречающихся слов в этом тексте. Ключ массива — слово, | |
значение — количество. Ни веб-сервер, ни база данных не понадобятся; версия php не имеет | |
значения. | |
*/ | |
function getWords(string $string): array | |
{ | |
if (!preg_match_all('/[a-zа-яёЁ]+/i', $string, $words, PREG_PATTERN_ORDER)) { | |
return []; | |
} | |
$words = array_count_values($words[0]); | |
rsort($words); | |
return array_slice($a, 0, 5, true); | |
} |
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
<script> | |
/* | |
1. Создать канвас 1000x1000 | |
2. Внутри создать прямоугольник посередине 200x100 | |
3. Сделать кнопку, которая увеличит прямоугольник до 300х200 и повернет его на 45 | |
градусов при этом он должен остаться также в середине | |
*/ | |
const canvas = { | |
create: function () { | |
this.canvas = document.createElement("canvas"); | |
this.canvas.width = 1000; | |
this.canvas.height = 1000; | |
this.rectWidth = 200; | |
this.rectHeight = 100; | |
this.ctx = this.canvas.getContext("2d"); | |
this.ctx.rect((this.canvas.width - this.rectWidth) / 2, (this.canvas.height - this.rectHeight) / 2, this.rectWidth, this.rectHeight); | |
this.ctx.fill(); | |
document.body.appendChild(this.canvas); | |
}, | |
update: function () { | |
if (!this.canvas) { | |
canvas.create(); | |
} | |
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); | |
this.ctx.beginPath(); | |
this.rectWidth = 300; | |
this.rectHeight = 200; | |
this.rectRotate = 45; | |
this.ctx.translate(this.canvas.width/2, this.canvas.height/2); | |
this.ctx.rotate(this.rectRotate * Math.PI / 180); | |
this.ctx.rect(-this.rectWidth/2, -this.rectHeight/2, this.rectWidth, this.rectHeight); | |
this.ctx.fill(); | |
} | |
} | |
canvas.create(); | |
canvas.update(); | |
<script> |
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
/* | |
Написать запрос для получения из таблицы с продуктами по 2 последних товаров из | |
каждой коллекции без использования HAVING. | |
*/ | |
/* v1 */ | |
SELECT Id, Name, Date, Id_collection, Price | |
FROM ( | |
SELECT Id, Name, Date, Id_collection, Price, @currentIdCollection := Id, @currentRank := IF(@currentIdCollection = Id_collection, @currentRank + 1, 1) AS currentRank | |
FROM products | |
ORDER BY Id_collection ASC, Date ASC | |
) productsRanked | |
WHERE currentRank <= 2; | |
/* v2 */ | |
SELECT Id, Name, Date, Id_collection, Price | |
FROM ( | |
SELECT Id, Name, Date, Id_collection, Price, ROW_NUMBER() OVER (PARTITION BY Id_collection ORDER BY Id_collection ASC, Date ASC) as currentRank | |
FROM products | |
ORDER BY Id_collection ASC, Date ASC | |
) productsRanked | |
WHERE currentRank <= 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment