amber tunnell

puts 'my thoughts on the magic that is code'

Sorting Algorithms Series: Merge Sort

| Comments

Merge Sort is a divide and conquer sorting algorithm. It is much more efficent than either Bubble Sort or Insertion Sort with an average and worst case time complexity of O(n log n).

In Merge Sort, you divide a list of items to be in the smallest units possible. You sort the smaller units, then repeatedly merge the small units back together until you have a sorted list.

  1. Take an array of items. Split the array into single subunits.
  2. Since an item with only one input is considered sorted, merge the subunits together so that you now have subunits with 2 items each.
  3. Sort each of these 2-item subunits so that they are all ordered correctly.
  4. Continue merging the subunits together and sorting them individually until you have a completely merged and sorted list.

All of the JavaScript: Basic terms and concepts for beginners

| Comments

When I first started learning JavaScript, I was thrown off by some of its terminology and quirks. This post is intended to offer some guidance into the craziness of the JavaScript world for beginning JavaScripters.

JavaScript is a dynamically-typed, object-oriented programming language that is usually used on the client side in web browsers.

Functions are central to one’s undertanding of JavaScript, so let’s start with the difference between function declarations and function expressions.

Sorting Algorithms Series: Insertion Sort

| Comments

Like Bubble Sort, Insertion Sort is a simple sorting algorithm.

Insertion Sort works by iterating up the current array, placing the current element into the correct place in the new sorted array.

  1. First, take the first element of the unsorted array out of the array and put it into an empty new array.
  2. Take the next element out of the unsorted array and place it into the new array. If it is smaller than the first element in the new array, swap them. If not, leave it at the end.
  3. Take the next element out of the array and put it at the end of the new array. If it is larger than the previous end element, leave it. If not, iterate through the array until you find its correct position and insert it there.
  4. Continue this process until your original array is empty and you have a new completely sorted array.

Sorting Algorithms Series: Bubble Sort

| Comments

When I was learning Ruby, we never discussed sorting algorithms. It’s my understanding that most sorting algorithm problems can be solved quite easily using built-in methods in most languages. That being said, it is important to understand the different sorting techniques available in computer science. Along those lines, here’s a series of blog posts on the most common sorting algorithms!

We’ll start with Bubble Sort.

Bubble Sort is a simple sorting algorithm.

  1. You start by comparing the first two items in an array. If the first item is larger than the second, you swap the two items.
  2. Then, you compare the second and third items. If the second is larger than the third, you swap them.
  3. Continue until you reach the end of the array.
  4. Then, you start from the beginning again and repeat the process until you have one full pass of the array in which you did not swap any items.
  5. You now have a sorted array!

Writing beautiful code with haml

| Comments

The more I code, the more I think of coding as an art form. Good code is easy to read by other humans, efficient, and easily adaptable. But great code is also elegant. When you look at a great piece of code, it feels right. Similarly, poorly written code, while often functional, just feels wrong and frustrating to look at.

Writing view templates using ERB, the default Rails templating language, has always seemed unnecessarily messy to me. ERB tags do not flow well with Ruby code or HTML tags. They are time-consuming to write in code. You also cannot use the command-slash commenting shortcut in Sublime Text with them; you must comment out each line of Ruby code separately (which makes them even more time-consuming to maintain).

Therefore, I was delighted when I discovered HAML (HTML abstraction markup language). A markup language that was designed to replace messy ERB templates with simpler, cleaner design. Why? Because markup should be beautiful.

Analyzing instance variables in Ruby

| Comments

Instance variables in Ruby can be accessed in two ways. Directly with an @ symbol, @variable, or through a method call, self.variable. Many Rubyists think these are synonymous. However, they are not.

By accessing the data through the method call, you are protecting the data from being accessed directly. Therefore, if the data changes unexpectedly, you will only have to adjust the one method. If you access the data directly throughout your code, you may have to change it many times so that your code doesn’t break.

It is a fine distinction, but can become an incredibly important one the larger your program is.

Ruby magic

| Comments

I’ve been learning Ruby for about 2-3 months now, and I’ve already fallen in love. Hard. The language is so intuitive that often I find myself trying methods in Ruby that I’ve never learned about just because I think there is a good chance they’ll work. And, often if they don’t do exactly what I thought they did, they still do something interesting that is awesome.

Useful Ruby resources

| Comments

After being at The Flatiron School for two weeks, I’ve come to realize that it’s all in the resources. Every task can be done quicker, smarter, and better with the right resources. Considering that, here’s an on-going list of awesome resources for the beginning Rubyist that I’ve learned about so far. If you know of other great resources not yet included, mention them in the comments!