Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Opposites attract

/*
// Timmy & Sarah think they are in love, but around where they live, they will only 
know once they pick a flower each. If one of the flowers has an even number of 
petals and the other has an odd number of petals it means they are in love.
// Write a function that will take the number of petals of each flower and return 
true if they are in love and false if they aren't.
*/

const lovefunc = (flower1, flower2) => {
  // More dynamic
  [flower1, flower2].filter(flower => flower % 2 === 0).length === 1
      // OR
  (flower1 + flower2) % 2 === 1
}

// With love @kouqhar
Source by www.codewars.com #
 
PREVIOUS NEXT
Tagged: #Opposites #attract
ADD COMMENT
Topic
Name
6+9 =