Select Page

## JavaScript Challenge Internship to CEO #13

Find the maximum number in an array of numbers.

The array: [-21, 113, -34, 1, -9, 5, 99, 1, 0].

## Explanation

To accomplish our task, we create a function called `findMax()` and pass in our array.

Inside the body, we need to create a variable referencing our found maximum value. We set the variable `max` to the first element of our array. Since this it the first maximum existing. We didn’t check any other so far.

The next step is to loop over the array and check if the element we are currently looking at is greater than our current max value.

If so, replace it to the newly found maximum element of `array`.

Once, we are done with iterating, comparing, and adding, just return the found maximum and print it to the console, and you are done!

## Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

## Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

## JavaScript Challenge Internship to CEO #12

Create a function that receives an array of numbers and returns an array containing only the positive numbers.

The array: [-65, 11, -5, 1, -19, 45, 19, 0, 1].

## Explanation

To accomplish our task, we create a function called `getPositives()` and pass in our array.

Inside the body, we need to create a new array (`tempArray`), to keep only the positives inside.

The next step is to loop over the already existing array and check if the element we are currently looking at is positive.

If so, add it to the newly created array of `tempArray`.

Once, we are done with iterating, checking and adding, just return the array and print it to the console, and you are done!

## Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

## Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

## JavaScript Challenge Internship to CEO #11

Calculate the average of the numbers in an array of numbers. The array: [2, 5, 17, 81, 9].

## Explanation

### How to calculate an average

A calculated „central“ value of a set of numbers.

To calculate it: add up all the numbers, then divide by how many numbers there are.

Example: what is the average of 2, 7 and 9?
Add the numbers: 2 + 7 + 9 = 18
Divide by how many numbers (i.e. we added 3 numbers): 18 ÷ 3 = 6
So the average is 6

(Also called the Arithmetic Mean.)

### Accomplishing our Goal

To accomplish our task, we create a function called `averageArray()` and pass in our array.

We need to get the length of the array for our for-loop. Creating a sum and then dividing by the length gets our average.

Just return the number and print it to the console, and you are done!

## Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

## Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

## JavaScript Challenge Internship to CEO #10

Calculate the sum of numbers in an array of numbers. The array: [1, 9, -19, 3, 5, 3, 7, 14, 91].

## Explanation

To accomplish our task, we need to iterate over the array and build the sum out of each element.

Since we aren’t so experienced right now, we should not use the reduce() function. Instead, we write basic operations like this with a for loop

After the loop has finished, we print it out to the console:

## Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

## Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/