 # HackerRank Sales by Match JavaScript Solution

For this weeks algorithm problem, we are given an array of integers representing the color of each sock, and set to determine how many pairs of socks with matching colors there are.

First, set a count of pairs of socks and sort the array we are given. Then we loop through the array n times. If the element at index[i] is the same as the next element, add 1 to pairs and continue the loop. Finally, return the total number of pairs.

--

--

# HackerRank Diagonal Difference JavaScript Solution

For this problem, you are given a square matrix and you need to find the absolute difference between the sums of its diagonals.

--

--

# React Routing

Now that my photo sharing app is growing, I need to add more pages and implement routing.

First, in the command line, `npm install react-router-dom`. Then, in `App.js` import`BrowserRouter`, `Routes`, `Link` and `Route` from `react-router-dom`.

## BrowserRouter

Adding `BrowserRouter` creates a base router, anything outside of it will be rendered on every page. If you have a NavBar, a header or a footer, leave them outside of the `BrowserRouter` scope.

## Routes

Next, adding `Routes` in the `BrowserRouter` scope you can add as many`Route` elements as you would like.

--

--

# Reverse a Linked List Hacker Rank Javascript Solution

My solution iterates over the list and changes the next of each node to the previous node. The order is important because we put node.next into temp before setting node.next to previous.

--

--

# My JavaScript Solution

First, I set the three variables. An array of lines which it the input split by each break. The amount of queries (length) and an empty array for the queue.

`const lines = input.split(/\r?\n/)const length = parseInt(lines)const queue = []`

Next, starting at index 1, I loop through the lines array length times. In the for loop I set a variable for the query, which it the first element for each line.

If the query is 1, add the number following the query to the end of the queue.

If the query is 2, remove the first element in the queue, if the queue exists.

If the query is 3, print the first element in the queue, if the queue exists.

--

--

# Big-O Notation

Big-O notation is a way to measure the time and space complexity of an algorithm. Specifically, Big-O describes the worst-case scenario for how long/how much space is used by an algorithm by always assuming the upper limit.

# Common Orders of Growth

## O(1)

This type of algorithm will always execute in the same time/space regardless of the size of the input data.

## O(n)

O(n) algorithms performance will grow in proportion to the size of the input data.

## O(N²)

O(N²) describes an algorithm that performs proportionally to the squared size of the input data. Common in algorithms that have nested data. For more deeply nested iterations O(N³), O(N⁴) and on are used.

## O(2^n)

This type of algorithm’s growth doubles with each additional data input. The growth is exponential.

--

--