$ brew update
$ brew install erlang
$ brew install elixir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write an algorithm to find the intersection of two users' love rectangles. | |
def intersection(rectangle1, rectangle2) | |
rect_hash1 = calc_space(rectangle1) | |
rect_hash2 = calc_space(rectangle2) | |
intersect_hash = overlap(rect_hash1, rect_hash2) | |
convert_to_rectangle(intersect_hash) | |
end | |
def calc_space(rectangle) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create anagram db | |
// str = "care race bear face heart earth etc" | |
function sortJoin(word) { | |
return word.split('').sort().join('') | |
} | |
function anagram(str){ | |
let words = str.split(' ') | |
let obj = {} | |
words.forEach(function(w) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_flat(arr, flat_arr=[]) | |
arr.each do |el| | |
el.is_a?(Array) ? make_flat(el, flat_arr) : flat_arr.push(el) | |
end | |
flat_arr | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch(name, options = nil) | |
if block_given? | |
options = merged_options(options) | |
key = namespaced_key(name, options) | |
#code omitted | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def expanded_key(key) # :nodoc: | |
return key.cache_key.to_s if key.respond_to?(:cache_key) | |
case key | |
when Array | |
if key.size > 1 | |
key = key.collect{|element| expanded_key(element)} | |
else | |
key = key.first | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def snakeit(sentence) | |
sentence.split.map do |word| | |
word.split("").map do |letter| | |
up_or_down(letter) | |
end.join() | |
end.join(" ") | |
end | |
def up_or_down(letter) | |
random_bool(letter) ? letter.upcase : letter.downcase |
$ iex
> :ets.new(:table, [:named_table])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rock, Paper, Scissors | |
# n = number of players | |
# players = string of letters "RPSPSSR" | |
defmodule RPS do | |
@winners %{"R" => "S", "S" => "P", "P" => "R"} | |
def find_winners(n, players) do | |
chars = String.split(players, "", trim: true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const update = (items) => { | |
items.map(update_item) | |
} | |
const update_item = (item) => { | |
switch (item.name) { | |
case "Sulfuras, Hand of Ragnaros": | |
return item | |
break | |
case "Aged Brie": |