https://www.codewars.com/kata/57f24e6a18e9fad8eb000296
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
Who remembers back to their time in the schoolyard, when girls would take a flower and tear its petals, saying each of the following phrases each time a petal was torn:
- "I love you"
- "a little"
- "a lot"
- "passionately"
- "madly"
- "not at all"
If there are more than 6 petals, you start over with "I love you" for 7 petals, "a little" for 8 petals and so on.
When the last petal was torn there were cries of excitement, dreams, surging thoughts and emotions.
Your goal in this kata is to determine which phrase the girls would say at the last petal for a flower of a given number of petals. The number of petals is always greater than 0.
코드
function howMuchILoveYou(nbPetals) {
const petals = ["I love you", "a little", "a lot", "passionately", "madly", "not at all"];
return petals[(nbPetals - 1) % petals.length]
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] You Can't Code Under Pressure #1 (8 kyu) / JavaScript (0) | 2023.03.04 |
---|---|
[Codewars] L1: Set Alarm (8 kyu) / JavaScript (0) | 2023.03.03 |
[Codewars] Simple multiplication (8 kyu) / JavaScript (0) | 2023.03.02 |
[Codewars] Keep up the hoop (8 kyu) / JavaScript (0) | 2023.03.02 |
[Codewars] Double Char (8 kyu) / JavaScript (0) | 2023.03.01 |
댓글