Posts

Showing posts from September, 2020

How to Uses Hashes, Maps, and Sets in JavaScript

Image
One of the first thing new JavaScript programmers learn is hashes.  Hashes are useful for saving data, nesting data, and in general having a faster Big-O lookup time than arrays*. *Do you know the reason that hashes have O(1) lookup time?  IT'S BECAUSE A HASH IS A FUNCTION !  You take in your hash keys, do a bunch of fancy math, and out pops a singular result for each key input.  It still sort of blows my mind that a hash is essentially the sort of thing we studied in Algebra 1, only you can input strings, numbers, whatever you want into a hash and it'll still spit out an answer.  Of course, all those strings and s and whatnot are of course binary numbers, so it makes a fair amount of sense when you think about it. If you had Aleph-One amount of memory, you could make a hash table for these functions. Hashes are useful for all sorts of things as well - the sorts of things you might encounter in code challenges in particular, like counting up how many of a thing ...

The Mathematics of Encryption

 asfdasfdasfd

Slice, Splice, and other ways of Discombobulating Your Arrays

Image
 If you're a bit like me, you're constantly mixing up slice  and splice , mostly because whoever named them foolishly decided to use nearly indistinguishable words for two thematically-related operations.  There is absolutely no good way to distinguish them - no funny puns, no thematic giveaways - so I'm making one right here right now: S lice L asers I ts C onstituents E way vs. S plice P olitely L ets I n C omponents E very time The hope here, of course, being that the most awful anagrams possible will do something to jog your memory when it's 3am and you need to either LASER CONSTITUENTS AWAY or LET COMPONENTS IN. Also difficult: figuring out where slice and splice do their slicing and splicing, and, very importantly, as one uses indexes and the other...doesn't. So, here we go: slice values declare where slice SLARTS and where it ENDS.  While splice has a "p" in it, so it does its changes in P lace. Here's a handy graphic: Ta-da! Now you know them f...

Bitwise Operations

Image
 When I was in 9th grade, I once spent the day going to school with my cousin.  At lunchtime, one of her friends was showing off a newfound skill: "I can count to ten in German! Eins, zwei, drei, vier, funf, sechs, sieben, acht, neun, zehn!" "That's nothing," I said, "I can count to ten in binary.  1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010!" No one got it.  And unfortunately, it seems like binary is also foreign to a lot of software developers as well. What is Binary? Binary is the two-digit radix (or base) system.  In the decimal system - what most people use on a daily basis - we use ten different digits (the Arabic numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to represent number values.  Numbers in the rightmost position before the decimal point represent that digit's value multiplied by ten to the zeroth power, and each position to the right increases the power of ten by one.  So 12 is actually another way of saying 1*10^1 + 2*10^0; 433 is equi...

Speed Testing - A Beginner's Primer

Image
For my final project at Flatiron, I scraped NFL scores off of ESPN's website, basically by downloading the entire html of the webpages I needed.  This meant that I had a lot of text to search through to find the scores that I needed - more than 20,000+ characters - and I needed to do this up to 32 times to find each team's score.  My initial attempt to parse the html involved converting the html to a string and using .slice to create a bunch of smaller strings that I could pick through looking for markups that indicated a team score was nearby.  This was slow - it took up to 20 seconds to find everything which was unacceptably slow, especially given that this one merely one step in getting users their score data. My solution? Using Ruby's .index command to find the markups I was looking for, and only then slicing off the data I needed.  Using this method, I reduced the time to generate my score data from 20 seconds to less than 1. I've always been interested in ...