coding & teaching with friends
I’m sitting here with my friends, and one of them wants me to help him with some programming. My friend Justin wants to learn a language that he can make money with once he learns it, so I suggested Javascript, even though I’m not particularly fond of it. My friend James suggested that as a first exercise, Justin create an array, and then write a function to sort it. I liked that idea, and as the teacher, I have to be able to do that myself. So here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
I unfortunately had problems with writing this. Not that a bubble sort is particularly hard or anything. No, my problem was i forgot line 6 - changing the arrayChanged
to false
. I blame this on the fact that in Haskell, you don’t need to do stuff like that because, well, you don’t have loops in Haskell like you do in most other languages. For example, I shall write me a bubble sort in Haskell:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
This took some trying also, but mostly because bubblesort is a very stateful algorithm, though it’s not too hard to figure out a way to deal with that.