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.
Here you can see a non optimized implementation of it:
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.
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 🙂
Java Script is not different then other languages ! It’s unique and special in its own way.
- For loops
- While loops
- Do – Then loops
- If – Else Statements
- Switch Statements
- Classes and Objects
- 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
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:
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.
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.