Today, we are going to be making a person (not in that sense, you) using a constructor function. When this function get’s called using the new keyword, it will construct and return an object, that’s why […]
Tag: objects
FCC Bonfire Series 137: Everything be true
Today, we’ll deal with objects, for objects are wonderful! Everything be true will have us write a function that takes in 2 arguments. The first will be an array of objects (also called a collection), and […]
FCC Bonfire Series 127: Sorted Union
This next bonfire challenge is a nice way of getting to know the arguments object. The arguments object is a local variable available within any function and contains an array of the arguments provided. Here’s an example:
function foo() { for (var i = 0; i < arguments.length; i++) { console.log(arguments[i]); } } foo('b', 'a', 'r', [0, 1, 2]); //-> b, a, r, [0, 1, 2]
The is something that must be on our minds at all times, although the arguments object seems to be an array and even has a length method (and callee and caller, you can read about them here) it actually isn’t, so no Array methods are available within it (say filter, reduce, forEach, etc).
Now that that’s out of the way, let’s get to it. We must write a function that given any number of arrays as arguments, it returns a single array containing unique values in the same order as the originally provided arrays:
unite([5, 6, 7], [2, 3, 5]); //-> [5, 6, 7, 2, 3] unite([1, 2, 3], [5, 2, 1, 4], [2, 1]); //-> [1, 2, 3, 5, 4]
There are quite a few ways of getting this done, we’ll go for the most simple solution, and I will let you come up with something else.
FCC Bonfire Series 116: Where art thou
Todays challenge will have us deal with objects; to be more concise, we are going to be working with object properties, or keys. We are tasked with writing a function that takes a list […]