Tech Junkie Blog: April 2018

Monday, April 30, 2018

The Array.concat() method returns a array that is a concatenation of the original array and what what is being passed into the concat() method.  The concat() method can take either values or another array.

For example lets say you have an array of numbers from 1 to 3

var numbers = [1,2,3];

Now let's say you want to concatenate the numbers 4 and 5 into the array.  You would type in the following

numbers.concat(4, 5);

The resulting array would be 1,2,3,4,5








or you can concatenate two arrays together, for example lets say you already declared the numbers array with the values 1,2,3 and you want to concatenate another array call numbers2 with the values 4,5,6 you can call the concat() method like the following

var numbers2 = [4,5,6];


Monday, April 23, 2018

The Array.sort() methods sorts the array in alphabetical order by default, or you can pass in a custom sort function.

So let's say you have an array of names that's our of order that you want to sort.


    <script>
        var names = ["zack", "jim", "bob", "adam", "jason"];
    </script>

If we call the names.sort() method we would get resulting array in Alphabetical order








Monday, April 16, 2018

The Array.reverse() method reverses the order of the array elements.  The easiest way to demonstrate this is to have an array with the numbers 1 to 5.  If we call the Array.reverse() method we should get an array of 5 to 1.  The Array.reverse() does not create a new array, it simply rearranges the array into a new order.  Just keep that in mind when you are using this method.

So let's declare our array from 1 to 5


    <script>
        var numbers = [1, 2, 3, 4, 5];
    </script>

So if we call the numbers.reverse() method we should get an array of 5 to one in the reverse order


Monday, April 9, 2018

The Array.join() method converts all of the elements of an array into strings and concatenates the elements.  If no delimiter is defined it is separated by a comma.  The most common use for this is to convert an array into a comma separated list of strings.

For example let's say we want to convert an array of zip codes into a comma separated list.

    <script>
        var zipCodes = [90210, 90211, 90212, 90213, 90214];
    </script>

If we just call the zipCodes.join() method we will get a string of comma separated list








Thursday, April 5, 2018

Wednesday, April 4, 2018

R is a programming language used by data scientists to present and manipulate data.  In this blog post I will go over the steps you need to do to install R in your Windows machine.

Here are the steps to install R:

1. Type the following URL into the address bar https://cran.r-project.org

2. Once you are on the page click on the link that says "Download R for Windows"

Tuesday, April 3, 2018

In CSS you can define styles for HTML elements and apply the styles globally on the page where the HTML element is used.  For example you can define styles for the entire html element or the p element.  Like the following markup


        html {color:blue;}
        p {font-weight:bold;}
        h1 {color:red;}

This is a paragraph

This h1 tag


You can also group your selectors by using commas to define a style for more than one element. Like h2, h3 {color: blue;}

This is h2

This is h3


So far we have define one declaration at a time. But in CSS we can chain together more than one declaration for each element. Let's say we want to make our h4 element a little bit more fancy by combining multiple declarations together.
h4 {font: 12px Ariel; color: green; background: yellow;}

This is the h4 style


Monday, April 2, 2018

JavaScript itself does not have multidimensional arrays, instead you can use an arrays of arrays instead.  Multidimensional arrays are basically arrays that you can reference by rows and columns.  The most obvious real world use is to store rows and columns of a database record.  Imagine if you have a row of the database product from the database from the table "Products".  Instead of storing each value in an individual variable you can store them in an arrays of arrays.

Let's say you have the following database Products table







This is a perfect scenario to use an arrays of arrays in JavaScript.

Here is how you would store the records, let's ignore the column headers and just concentrate on the record rows and columns.