Skip to content

Instantly share code, notes, and snippets.

View blake41's full-sized avatar

Blake Johnson blake41

  • http://blakejohnson.brandyourself.com/
View GitHub Profile
@blake41
blake41 / interview1.md
Last active December 20, 2015 16:09
interview questions

What is a closure?

How do we implement/create/use a closure in Ruby?

What's the difference between a closure in JS vs Ruby?

Why do we use closures so much more in JS as opposed to Ruby?

What is the Ruby analog of an anonymous function in Javascript?

what is a linked list?

how is a linked list different than an array?

why have you never heard of a linked list before?

how would you implement a linked list in ruby?

wikipedia

def flatten(array)
container = []
array.each do |element|
if element.is_a?(Array)
sub = flatten(element)
container += sub
else
container += [element]
end
end
@blake41
blake41 / collections practice
Last active December 28, 2015 10:09
practice manipulating arrays, strings, numbers and hashes
Collections Practice
1. sort the following array in ascending order
["blake", "ashley", "scott"]
2. sort the following array in descending order
["blake", "ashley", "scott"]
3. put the following array in reverse order
["blake", "ashley", "scott"]
4. grab the second element in the array
["blake", "ashley", "scott"]
@blake41
blake41 / pigeon solution
Created November 18, 2013 22:14
pigeons
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
:white => ["Queenie", "Andrew", "Ms .K", "Alex"],
:brown => ["Queenie", "Alex"]
},
:gender => {
:male => ["Alex", "Theo", "Peter Jr.", "Andrew", "Lucky"],
:female => ["Queenie", "Ms .K"]
def first_even(items)
#code goes here
end
Organizing Nested Data
I have a collection of Programming Languages.
languages = {
:oo => {
:ruby => {
:type => "interpreted"
},
:javascript => {
:type => "interpreted"
@blake41
blake41 / maze.txt
Last active December 28, 2015 19:38
Build a maze solver
###########
# #
# ##### # #
# # #
### # ### #
# # #
# # ### ###
# # #
# ### # # #
# # #