Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
graph = {}

graph["you"] = ["alice", "claire", "bob"]
graph["bob"] = ["peggy", "anuj"]
graph["alice"] = ["peggy"]
graph["claire"] = ["jonny", "thom"]
graph["anuj"] = []
graph["peggy"] = []
graph["jonny"] = []
graph["thom"] = []

bfs = (name) ->
deque = graph[name][..]
checked = []

while deque.length > 0
pessoa = deque.shift()

if pessoa not in checked
if personIsSeller(pessoa)
return true
else
deque = deque.concat(graph[pessoa])
checked.push(pessoa)

return false


personIsSeller = (name) ->
name[name.length - 1] is "m"

console.log bfs("you")
12 changes: 12 additions & 0 deletions 06_breadth-first_search/coffeescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## How to Run the Algorithm

```
# Install CoffeeScript
npm install -g coffeescript

# Run directly
coffee 01_breadth-first_search.coffee

# Or compile and run
coffee -c 01_breadth-first_search.coffee && node 01_breadth-first_search.js
```