 # Birthday Cake Candles Solution in Javascript

by Travis Scott Lee

Problem

You are in charge of the cake for a child’s birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Example

candles = [4,4,1,3]

The maximum height candles are 4 units high. There are 2 of them, so return 2.

Function Description

Complete the function `birthdayCakeCandles` in the editor below.

birthdayCakeCandles has the following parameter(s):

• int candles[n]: the candle heights

Returns

• int: the number of candles that are tallest

Input Format

The first line contains a single integer, n, the size of candles[].
The second line contains n space-separated integers, where each integer i describes the height of candles[i].

Constraints

• 1 ≤ n ≤ 10⁵
• 1 ≤ candles[i] ≤ 10⁷

Solution

--

--

# Simple Array Sum Solution in Javascript

by Travis Scott Lee

Problem

Given an array of integers, find the sum of its elements.

For example, if the array ar = [1,2,3], 1 + 2 + 3 = 6, so return 6.

Function Description

Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.

simpleArraySum has the following parameter(s):

• ar: an array of integers

Input Format

The first line contains an integer, n, denoting the size of the array.
The second line contains nspace-separated integers representing the array’s elements.

Constraints

0 < n, ar[i] ≤ 100

Solution

First, we create a const called reducer which will serve as a function in reducing the array. Then, we set the sum equal to the arr with the reduce function along with the reducer callback. Finally, we return the sum.

--

--