WTF is Bubble Sort ?

Bubble sort is a type of sorting algorithm. Its not the best for everything but it does have its uses. It gets its name since it makes the largest values “bubble” to the top. Bubble sort does its job by using pair comparisons. So it takes the current value and compares it to it’s neighbor directly to the right.

Below you can see what I mean. We first take 5 and compare it 3, then ask the question “is 5 greater then 3 ? ” Then if it is, 5 switches places with 3 and if it isn’t then they stay in the same place, and move on to the next value.

BubbleSortEx1

Here you can see a non optimized implementation of it:

 

Map vs Reduce vs Filter in JavaScript

So these methods are part of the “functional” aspect of JavaScript. JavaScript is a strange language in a good way. Before we get into this, know that all these methods above try to replace the “for” loop, or any other type of loop you can think of.

Some of you might be saying, “I like my loops thank you very much, it is in every language out there !”. And yes that is very true, however these make writing a whole loop for something trivial a thing of the past. So lets get on with it, its not as hard as you probably things it is.

All these methods only working on arrays. And they never modify the array you apply them to. They just return a new array.

MAP

As in Mapping “X” to “Y”, or transforming X into Y. In the case of JavaScript you are making a map of your values. You basically just give it a function (could be anonymous) and it applies it to each array element, and forms a new array.

REDUCE

As in reducing something to its essence, or compressing something down. In the case of JavaScript you are taking all your values in an array, and compressing them into something useful.

FILTER

As in finding something based on a certain set of parameters. I think you guys kinda already know what this particular method does.

I hope this helped you better understand Reduce, Map, and Filter 🙂

JS for beginners, the TLDR version – Part 1

Java Script is not different then other languages ! It’s unique and special in its own way.

JavaScript has everything you would expect to find all computer programming languages:

  • For loops
  • While loops
  • Do – Then loops
  • If – Else Statements
  • Switch Statements
  • Classes and Objects
  • Functions
  • Dynamically Typed (most languages have this)

However it has some very weird and interesting differences:

  • It has no truth, it is a truthy language
  • You can stuff a function into a variable
  • There are more ways then one to do the same thing

Getting Started with Express.js

Intro

Raise your hand if you already know the MVC design pattern ! … oh right you can’t.

You can look at one of my previous blog posts here. Now that we have gotten that out of the way. Express.js provides an incredibly simplistic and transparent way to develop APIs for your applications. It’s one of the most popular frameworks to run on the Node.js platform.

You simply define your routes, define what you want to send out and pull in, and your golden 👍

Setting it up:

Routes:

Here you can see the route in question is just a slash. That means that when ever anyone hits the https://”your domain”/, this route gets triggered (since it is a GET request). Once the route gets triggered it executes the function, that has the “req”, and “res” variables. The “req” is your request object, and the “res” is your response object. You can put different things in the res object and it gets passed along to be rendered in HTML.

This same sort of logic can be applied to POST and PUT requests.

Folder Structures:

You can use a variety of different folder structures. What ever folder structure you use, make sure its suited for the type of app your going to be building. You can checkout an example over here.

And your done ! Easy as that. You may be thinking WTF is that really it ? Why do people want to use Express.js if this is it ? Well the answer is that the frame work does not lock you into, using any specific way of doing things. Therefor you can use any sort of authentication, object relational mapper, session manager, or data base you want.

You can find the best 40 packages most commonly used here.