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
class Queue { | |
constructor() { | |
this.items = []; | |
} | |
enq(obj) { | |
this.items.push(obj); | |
} | |
deq() { |
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
class Queue { | |
constructor() { | |
this.items = []; | |
} | |
enq(obj) { | |
this.items.push(obj); | |
} |
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
class Node | |
attr_reader :value, :children,:distance | |
attr_writer :distance | |
def initialize(value, children = []) | |
@value = value | |
@children = children | |
@distance = 0 | |
end | |
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
defmodule Words do | |
@doc """ | |
Count the number of words in the sentence. | |
Words are compared case-insensitively. | |
""" | |
@spec count(String.t) :: map() | |
def count(sentence) do | |
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
defmodule TodoAgent do | |
def create_list do | |
Agent.start_link(fn -> [] end) | |
end | |
def add_todo(todo_list, todo) do | |
Agent.update(todo_list, fn(todos) -> [todo | todos] end ) | |
end | |
def remove_todo(todo_list, todo) do |
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
defmodule MyApp do | |
use Application | |
# See http://elixir-lang.org/docs/stable/elixir/Application.html | |
# for more information on OTP Applications | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
worker(Todo, [[]]) |
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
defmodule MyApp do | |
use Application | |
# See http://elixir-lang.org/docs/stable/elixir/Application.html | |
# for more information on OTP Applications | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
worker(Todo, [[]]) |
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
defmodule Todo do | |
use GenServer | |
# wrap calls to GenServer in public functions | |
def start(list) do | |
{:ok, todo_list} = GenServer.start(__MODULE__,list) | |
todo_list | |
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
defmodule ListReverse do | |
def reverse(list) do | |
reverse(list,[]) | |
end | |
defp reverse([h|t],result) do | |
reversed = [h] ++ result | |
reverse(t,reversed) | |
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
defmodule ListSum do | |
def sum(list) do | |
sum(list,0) | |
end | |
defp sum([h|t],total) do | |
sum(t, total + h) | |
end | |
defp sum([],total) do |