Wiki Elegant

Medium

Which Generation Are You?

Which Generation Are You? Try finding your ancestors and offspring with code. Create a function that takes a number x and a character y (“m” for male, “f” for female), and returns the name of an ancestor (m/f) or descendant (m/f). If the number is negative, return the related ancestor. If positive, return the related descendant. You are generation 0. In the case of 0 (male or female), return “me!”. Examples generation(2, “f”) …

Which Generation Are You? Read More »

How Much is True?

How Much is True? Create a function which returns the number of true values there are in an array. Examples countTrue([true, false, false, true, false]) ➞ 2 countTrue([false, false, false, false]) ➞ 0 countTrue([]) ➞ 0 Notes Return 0 if given an empty array. All array items are of the type bool (true or false). Answer (1) const countTrue = r …

How Much is True? Read More »