Created
July 29, 2024 07:41
-
-
Save EntaltsevSN/75ebf110f14436922adfbb0c1c74455f to your computer and use it in GitHub Desktop.
Подсчёт рукопожатий с постепенным увеличением количества участников
This file contains hidden or 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
| // Объявляем динамические переменные | |
| let people = 0, | |
| handshakes = 0, | |
| log = []; | |
| // Объявляем постоянные переменные | |
| const targetPeople = 10; | |
| const completeHandshaking = () => { | |
| const report = log.map(({ people, handshakes }) => | |
| `С приходом ${people} человека стало ${handshakes} рукопожатий\n` | |
| ).join('') | |
| const result = `Всего с приходом ${people} человек произошло ${handshakes} рукопожатий` | |
| alert(`${report} ${result}`) | |
| } | |
| // Объявляем подсчет рукопожатий | |
| const countAHandshakes = () => { | |
| // Проводим цикл обновления рукопожатий с приходом человека | |
| while (people < targetPeople) { | |
| // Приглашаем нового человека | |
| people++; | |
| // Досчитывать рукопожатия, если больше 1 человека в комнате | |
| if(people > 1) { | |
| handshakes += people - 1; | |
| // Записываем, сколько рукопожатий стало с приходом человека | |
| log.push({ people, handshakes }) | |
| } | |
| } | |
| completeHandshaking(); | |
| } | |
| countAHandshakes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment