Tech Junkie Blog: May 2018

Monday, May 28, 2018

The filter() method returns the elements of the array that satisfies the function that is passed into the method.  If the function returns true the element is added to the filtered array, else it is ignored.

Let's say we only want to buy oil when the prices drops below $72, so we will only return an array element where the prices below $72


    <script>
        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var lowPrices = oilPrices.filter(function (value) { return value < 72 });

        console.log(lowPrices);
    </script>


Monday, May 21, 2018

The map() method is similar forEach() method which means that it performs a function, however it returns a new array with the returned values.  In this example we are going to perform the $1 discount of the oil prices using the map() method instead of the forEach() the difference here is that the map() method returns a new array instead of the original array, but the result will be the same.


    <script>
        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var discounted = oilPrices.map(function (value) { return value -1; });

        console.log(discounted);
    </script>


The code above calls the map() method on the oil prices and returns a discounted value of $1 for each array element


Thursday, May 17, 2018

R is a programming language that is a little different in syntax then your typical mainstream languages like Java or C#. In this post we will go over how to create variables in R.

Let's create some variables about a user:

To create a variable in we use the <- key for example if you want to assign a value to variable firstName, you would write firstName <-  "John" or "John" -> firstName










If you type in the firstName in the console you will "John" as the value









To get the type of the variable you can use the class(firstName)











Monday, May 14, 2018

The forEach() method loops through an array, and performs a function on each element of the array.  The forEach() method can take three arguments, the first argument is a current value that you want to perform an action on.  The second argument acts as the "this" value within the scope of the function.  The third argument is the array itself.  Most of the time only the first argument is passed.  The code below passes in only one argument which is an anonymous function being performed on each element of the array using the forEach() method to calculate the oil prices in the last five days and prints it out in the console.


    <script>
        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];
        var total = 0;

        oilPrices.forEach(function (value) { total += value });

        console.log(total);
    </script>

You should get the total of 362.19 as your total when you add up the last five days of oil prices.







Thursday, May 10, 2018

Now that we R installed in Visual Studio let's install some of the more useful packages that we will use in our R development.  Packages provides you  with the tools to perform tasks, functionalities and datasets for the those features.

To install R devtools package do the following:

In your R project, type the following command into the R Interactive window install.packages("devtools")







A list of installed packages will be installed






















Now that we've installed the devtools package we need to run the library command to use them by typing library(devtools) in the R Interactive window


Monday, May 7, 2018

The JavaScript array splice() method allows you to delete and insert array elements in one method
Before we get to the examples let's see how we would use the splice() method on an array first.

The splice method takes 1....n method parameters.  The first parameter specify the position of the array that will be deleted.  The second parameter specify the number of elements to be deleted after the first element's index position, or splice out.  Any subsequent parameters will be the elements that will be added to the array.  If there's only one parameter then all the elements before the first parameter's position will be deleted

For example let say we have the following array

    <script>
        var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9,10];
    </script>

In this example we deleted everything that is before the array index 2 by typing numbers.splice(2).  As you can since we only have 1 parameter passed in the elements after the index 2 is spliced out and the numbers array is changed to have just two elements 1,2.  The splice() method changes the original array.











Wednesday, May 2, 2018

In this post we are going to go over the steps to install R Tools For Visual Studio 2017.  RStudio has a development environment that is bare bones for the free version.  Visual Studio 2017 offers a more robust development environment if you download the R Tools feature.

Here are the steps to install R Tools for Visual Studio:

1. Click on Tools → Get Tools and Features










2.  This will launch the Visual Studio Installer, click on "Modify" on your installed version























Tuesday, May 1, 2018

In CSS you can group your selects into one declarations. For example you want to create a read alert text for your h2 HTML element tag.

You can define each property one at a time like so

<style>
        h2{font: bold 25px arial, verdana;}
        h2{color: red;}
        h2{background:black;}
</style>


When you type in <h2>Alert</h2> you will get this effect





You can achieve the same effect by grouping the selectors into one declaration like the following.

    <style>
        h2 {
            font: bold 25px arial, verdana;
            color: red;
            background: black;
        }
    </style>

As you can see it is much cleaner and easier to read.