The goal of this exercise is to take an array of items: objects, arrays, numbers, strings and null, and return only true objects. Both null and arrays are objects in Javascript, so I have to test for those specifically. First I used the reduce method. On line 7, I test if an item is null […]

# Posts from April 2018

# Javascript Problems – Sum two numbers

In this problem, I create a function that either takes in two arguments to be added OR is invoked twice to add the numbers. On line 6, I test to see if there is no argument b. If there is no argument b, I run an anonymous function that takes in the argument from the second […]

# Javascript Map Method

The map() method can be used to modify all elements of an array. Below, I have a function that will take an array of sales prices, and mark them up by 10% to account for sales tax. On line 3, if I return the item without the parseFloat function, it converts all the elements in […]

# Javascript Reduce Method

I have been studying the reduce() method in Javascript, which can be used to distill an array down to a single item (or multiple items, but less than the number in the original array). By contrast, the map() method will modify elements in an array, but will return an array of the same length, or […]

# Javascript Problems – Averaging an Array

This problem came from the Colt Steele Udemy JS Bootcamp. He is introducing Node, and the problem is to average an array. I had to review my array summing options. I did it two ways — the first using the forEach() method, and the second using the reduce() method. Once I have the sum of […]

# Patatap Game

This was a fun exercise from the Colt Steele developer bootcamp using Paper.js to make circles and Howler.js to create a sound. If you type on a letter key, it creates a colored circle that that fades off the screen while it plays a tone. This was done using basic Javascript with the Paper and Howler […]

# Javascript Recursion

I’m working on some problems to help me better understand recursion. First, I will do a function to calculate n factorial (n!). This is how Wikipedia explains factorial: In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, https://en.wikipedia.org/wiki/Factorial The example below is a good case for using a […]

# Javascript Problems – Fibonacci Sequence

The Fibonacci Sequence starts with the numbers 0 and 1, the sequence starts by adding 0+1 = 1, and then adding the last two numbers so that 1 + 1 = 2, 2+1 =3, 2+3=5. You end up with the sequence [0,1,1,2,3,5,8,13…] https://en.wikipedia.org/wiki/Fibonacci_number Option 1 – Iterative Solution For my first attempt, I made an iterative […]