Wiki Elegant

Check If the Brick Fits through the Hole

Check If the Brick Fits through the Hole Write the function that takes three dimensions of a brick: height(a), width(b) and depth(c) and returns true if this brick can fit into a hole with the width(w) and height(h). Examples doesBrickFit(1, 1, 1, 1, 1) ➞ true doesBrickFit(1, 2, 1, 1, 1) ➞ true doesBrickFit(1, 2, 2, 1, …

Check If the Brick Fits through the Hole Read More »

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 »

Instances of the Fibonacci Sequence

Instances of the Fibonacci Sequence Create a function that takes a number as an argument and returns n instances of the Fibonacci sequence as an array. Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1. So the easy explanation is: The next element is the sum of the two previous elements. If you want …

Instances of the Fibonacci Sequence 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 »