## DEV Community is a community of 752,525 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

dev.to staff

Posted on

# Daily Challenge #140 - I love you, a little, a lot, passionately ... not at all

Remember back to your 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
• not at all

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 for a flower of a given number of petals, where `nb_petals > 0`.

This challenge comes from nbeck on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

## Discussion (9)

SavagePixie • Edited on

JavaScript:

``````const responses = [
"not at all",
"I love you",
"a little",
"a lot",
"passionately",
]

const getLove = n => responses[n % 6]
``````
Hao

Just two improvements:

• `(n + 6) % 6` seems a little bit redundant here, `n % 6` does the same thing.
• Flower with only one petal should return `not at all`, but this returns `I love you`.
Nick Holmes

You're right about the (n+6)%6 (its correct, but the +6 does nothing).

However, SavagePixie cleverly rotated the items in the array down one position, to essentially pre-calculate the -1 offset for the first item - so its working correctly.

Hao

Ah, I see. Didn't pay attention there, my bad. Thanks for the explanation. 😀

SavagePixie • Edited on

Thanks for your feedback! I wasn't sure how the operator `℅` would work when the result of the division is smaller than one and had no time to test it, so I went for an option I was sure would work. I'll change my solution accordingly.

Hao

Here's one solution using scss:

@nobody

💚Allons y Clojure: 💙

``````(ns affairs)

(defonce ^:private Love
"cause affairs on the heart are private and unique"
(fn [n]
(let [petals ["yes" ;; changed from "I love you" for semantics
"a little"
"a lot"
"passionately"
"not at all"]]
(when (> (int n) 0)
(get petals (mod  (+ (int n) (count petals))
(count petals))))
))

``````
erezwanderman

JS

``````f = nb_petals => {switch(nb_petals % 6) { case 0: return 'not at all'; case 1: return 'I love you'; case 2: return 'a little'; case 3: return 'a lot'; case 4: return 'passionately'; case 5: return 'madly';}}
``````
Victor Lazo Dominguez

JS a little bit traditional. I used the array created by SavagePixie. Thanks

const responses = [
"not at all",
"I love you",
"a little",
"a lot",
"passionately",