From 2c821063c3c638ff48baafcd4fbff0530bc51bc9 Mon Sep 17 00:00:00 2001 From: Akex <a.plokhikh.sas@gmail.com> Date: Thu, 4 Apr 2024 11:03:54 +0500 Subject: [PATCH 1/3] first task done --- app/index.php | 10 ++++++++++ app/repository/SortPrice.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 app/repository/SortPrice.php diff --git a/app/index.php b/app/index.php index e69de29..c228b39 100644 --- a/app/index.php +++ b/app/index.php @@ -0,0 +1,10 @@ +<?php +require_once('repository/SortPrice.php'); + +$array = [ ['price'=>10, 'count'=>2], ['price'=>5, 'count'=>5], ['price'=>8, 'count'=>5], ['price'=>12, 'count'=>4], ['price'=>8, 'count'=>4], ]; +$array = sortPrice($array); +var_dump($array); + + + + diff --git a/app/repository/SortPrice.php b/app/repository/SortPrice.php new file mode 100644 index 0000000..2b7a69d --- /dev/null +++ b/app/repository/SortPrice.php @@ -0,0 +1,31 @@ +<?php +/** + * ВыполнÑет Ñортировку маÑÑива по убыванию цены + * @param array $array + * @return array + */ +function sortPrice(array $array): array { + $keyPriceArray = []; + + foreach ($array as $tuple) { + $key = $tuple['price']; + $item = $tuple['count']; + $keyPriceArray[$key][] = $item; + } + krsort($keyPriceArray); + + $returnableArray = []; + foreach ($keyPriceArray as $key => $item){ + asort($item); + foreach ($item as $oneOfItem){ + $returnableArray[] = [ + [ + 'price'=>$key, + 'count'=>$oneOfItem + ] + ]; + } + } + + return $returnableArray; +} \ No newline at end of file -- GitLab From 19e7f6962ff5f239ef5b818b5d22aae397a20909 Mon Sep 17 00:00:00 2001 From: Akex <a.plokhikh.sas@gmail.com> Date: Thu, 4 Apr 2024 12:10:43 +0500 Subject: [PATCH 2/3] finish --- app/index.php | 6 +++--- app/repository/SlpitKeyValue.php | 19 +++++++++++++++++++ app/repository/SortPrice.php | 31 ------------------------------- app/repository/UniqElements.php | 25 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 app/repository/SlpitKeyValue.php delete mode 100644 app/repository/SortPrice.php create mode 100644 app/repository/UniqElements.php diff --git a/app/index.php b/app/index.php index c228b39..4a38308 100644 --- a/app/index.php +++ b/app/index.php @@ -1,8 +1,8 @@ <?php -require_once('repository/SortPrice.php'); +require_once('repository/UniqElements.php'); -$array = [ ['price'=>10, 'count'=>2], ['price'=>5, 'count'=>5], ['price'=>8, 'count'=>5], ['price'=>12, 'count'=>4], ['price'=>8, 'count'=>4], ]; -$array = sortPrice($array); +$arr = [ ['laravel', 'php'], ['codeigniter', 'php'], ['laravel', 'php'], ['c++', 'java'], ]; +$array = uniqElements($arr); var_dump($array); diff --git a/app/repository/SlpitKeyValue.php b/app/repository/SlpitKeyValue.php new file mode 100644 index 0000000..738b5c2 --- /dev/null +++ b/app/repository/SlpitKeyValue.php @@ -0,0 +1,19 @@ +<?php +/** + * РазделÑет двумерный маÑÑив на ключ и маÑÑив значенй + * @param $array array + * @return array + */ +function splitKeyValue($array): array { + $returnableArray = []; + + foreach ($array as $tuple) { + $key = $tuple[0]; + $item = $tuple[1]; + $returnableArray[$key][] = $item; + } + return $returnableArray; +} +{ + +} \ No newline at end of file diff --git a/app/repository/SortPrice.php b/app/repository/SortPrice.php deleted file mode 100644 index 2b7a69d..0000000 --- a/app/repository/SortPrice.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** - * ВыполнÑет Ñортировку маÑÑива по убыванию цены - * @param array $array - * @return array - */ -function sortPrice(array $array): array { - $keyPriceArray = []; - - foreach ($array as $tuple) { - $key = $tuple['price']; - $item = $tuple['count']; - $keyPriceArray[$key][] = $item; - } - krsort($keyPriceArray); - - $returnableArray = []; - foreach ($keyPriceArray as $key => $item){ - asort($item); - foreach ($item as $oneOfItem){ - $returnableArray[] = [ - [ - 'price'=>$key, - 'count'=>$oneOfItem - ] - ]; - } - } - - return $returnableArray; -} \ No newline at end of file diff --git a/app/repository/UniqElements.php b/app/repository/UniqElements.php new file mode 100644 index 0000000..8966c71 --- /dev/null +++ b/app/repository/UniqElements.php @@ -0,0 +1,25 @@ +<?php +require_once ('SlpitKeyValue.php'); +/** + * Удалить дубликаты, оÑтавив только уникальные Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ + * @param array $array + * @return array + */ +function uniqElements(array $array): array { + $splitedArray = splitKeyValue($array); + + $returnableArray = []; + foreach ($splitedArray as $key => $item){ + $item = array_unique($item); + foreach ($item as $oneOfItem){ + $returnableArray[] = [ + [ + $key, + $oneOfItem + ] + ]; + } + } + + return $returnableArray; +} \ No newline at end of file -- GitLab From 13ff85e9319f0e6583916153d3303d20eafc4a7e Mon Sep 17 00:00:00 2001 From: Akex <a.plokhikh.sas@gmail.com> Date: Tue, 9 Apr 2024 01:04:32 +0500 Subject: [PATCH 3/3] fix naming --- .../issuestore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d | 3 +++ .idea/sonarlint/issuestore/index.pb | 3 +++ .../b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d | 0 .idea/sonarlint/securityhotspotstore/index.pb | 3 +++ .../SlpitKeyValueRepository.php} | 0 .../UniqElements.php => Repository/UniqElementsRepository.php} | 2 +- app/index.php | 2 +- 7 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .idea/sonarlint/issuestore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d create mode 100644 .idea/sonarlint/issuestore/index.pb create mode 100644 .idea/sonarlint/securityhotspotstore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d create mode 100644 .idea/sonarlint/securityhotspotstore/index.pb rename app/{repository/SlpitKeyValue.php => Repository/SlpitKeyValueRepository.php} (100%) rename app/{repository/UniqElements.php => Repository/UniqElementsRepository.php} (92%) diff --git a/.idea/sonarlint/issuestore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d b/.idea/sonarlint/issuestore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d new file mode 100644 index 0000000..e0cd4e4 --- /dev/null +++ b/.idea/sonarlint/issuestore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d @@ -0,0 +1,3 @@ + +w php:S6600"5Remove the parentheses from this "require_once" call.(¯¸§ð8Õª½úë1J$90f6c8bc-93bc-4077-bbaa-7c4a2d99c857 +“ php:S4833"QReplace "require_once" with namespace import mechanism through the "use" keyword.(¯¸§ð8Öª½úë1J$d23cf82e-caac-43b4-b8cf-9b7b260fc815 \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..aaa01d0 --- /dev/null +++ b/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,3 @@ + += + app/index.php,b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d b/.idea/sonarlint/securityhotspotstore/b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..aaa01d0 --- /dev/null +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -0,0 +1,3 @@ + += + app/index.php,b/3/b3dc76f2dddfb1a5254e54207056e7abe051447d \ No newline at end of file diff --git a/app/repository/SlpitKeyValue.php b/app/Repository/SlpitKeyValueRepository.php similarity index 100% rename from app/repository/SlpitKeyValue.php rename to app/Repository/SlpitKeyValueRepository.php diff --git a/app/repository/UniqElements.php b/app/Repository/UniqElementsRepository.php similarity index 92% rename from app/repository/UniqElements.php rename to app/Repository/UniqElementsRepository.php index 8966c71..763b55b 100644 --- a/app/repository/UniqElements.php +++ b/app/Repository/UniqElementsRepository.php @@ -1,5 +1,5 @@ <?php -require_once ('SlpitKeyValue.php'); +require_once('SlpitKeyValueRepository.php'); /** * Удалить дубликаты, оÑтавив только уникальные Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ * @param array $array diff --git a/app/index.php b/app/index.php index 4a38308..154c165 100644 --- a/app/index.php +++ b/app/index.php @@ -1,5 +1,5 @@ <?php -require_once('repository/UniqElements.php'); +require_once('Repository/UniqElementsRepository.php'); $arr = [ ['laravel', 'php'], ['codeigniter', 'php'], ['laravel', 'php'], ['c++', 'java'], ]; $array = uniqElements($arr); -- GitLab