Wiki Elegant

# Javascript

Javascript Challenges

## 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, …

## 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”) …

## Function Factory

Function Factory Create a function that takes a “base number” as an argument. This function should return another function which takes a new argument, and returns the sum of the “base number” and the new argument. Please check the examples below for a clearer representation of the behavior expected. Examples // Calling makePlusFunction(5) returns a …

## Histogram Function

Histogram Function Build a function that creates histograms. Every bar needs to be on a new line and its length corresponds to the numbers in the array passed as an argument. The second argument of the function represents the character to be used for the bar. histogram(arr, char) ➞ str Examples histogram([1, 3, 4], “#”) ➞ …

## 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 …

## 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 …