Skip to content

Commit 4632697

Browse files
c252berquist
authored andcommitted
implemented bubblesort in coffeescript and added it to book.json (algorithm-archivists#651)
1 parent e73f5f1 commit 4632697

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ indent_size = 0
157157
trim_trailing_whitespace = false
158158
insert_final_newline = false
159159
end_of_line = lf
160+
161+
# CoffeeScript
162+
[*.coffee]
163+
indent_style = space
164+
indent_size = 2

book.json

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@
193193
"lang": "ss",
194194
"name": "Scheme"
195195
},
196+
{
197+
"lang": "coffee",
198+
"name": "CoffeeScript"
199+
},
196200
{
197201
"lang": "kotlin",
198202
"name": "Kotlin"

contents/bubble_sort/bubble_sort.md

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
7272
<p>
7373
<img class="center" src="code/scratch/bubble_sort.svg" width="400" />
7474
</p>
75+
{% sample lang="coffeescript" %}
76+
[import:1-6, lang:"coffeescript"](code/coffeescript/bubblesort.coffee)
7577
{% endmethod %}
7678

7779
... And that's it for the simplest bubble sort method.
@@ -147,6 +149,8 @@ Trust me, there are plenty of more complicated algorithms that do precisely the
147149
[import, lang:"bash"](code/bash/bubble_sort.bash)
148150
{% sample lang="scratch" %}
149151
The code snippet was taken from this [Scratch project](https://scratch.mit.edu/projects/316483792)
152+
{% sample lang="coffeescript" %}
153+
[import, lang:"coffeescript"](code/coffeescript/bubblesort.coffee)
150154
{% endmethod %}
151155

152156
<script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bubbleSort = (a) ->
2+
n = a.length
3+
for i in [0 .. n]
4+
for j in [0 .. n - 1]
5+
if a[j] > a[j + 1]
6+
[a[j + 1], a[j]] = [a[j], a[j + 1]]
7+
8+
main = () ->
9+
a = [1, 3, 2, 4, 5, 10, 50, 7, 1.5, 0.3]
10+
bubble_sort(a)
11+
console.log(a)
12+
13+
main()

0 commit comments

Comments
 (0)