js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Solve 'I love you, a little , a lot, passionately ... not at all' #274

Closed odv closed 5 years ago

odv commented 5 years ago

https://www.codewars.com/kata/i-love-you-a-little-a-lot-passionately-dot-dot-dot-not-at-all/train/javascript

RazvanBugoi commented 5 years ago
function howMuchILoveYou(nbPetals) {
   const input = nbPetals;
   const arr = ["I love you", "a little", "a lot", "passionately", "madly", "not at all"];
   let output = [];
   for (let i = 0; i < input; i += 1) {
     output.push(arr[i % arr.length]);
     }
     return output[output.length - 1];
  }

I must confess that for this one I had to google "how to iterate over an array multiple times".