Skip to content

Instantly share code, notes, and snippets.

@klandergren
klandergren / gist:1080675
Created July 13, 2011 16:23 — forked from gvinter/gist:1080478
Configurable hash functions
function max(a, b) {
this.a = a;
this.b = b;
if (a > b) {
return a;
} else {
return b;
}
}
@klandergren
klandergren / gist:1042657
Created June 23, 2011 14:40 — forked from gvinter/gist:1042629
BubbleSort
// working version
function swap(a_array, i, j) {
var tmp = a_array[i];
a_array[i] = a_array[j];
a_array[j] = tmp;
}
function bubble_sort(an_array){
var n = an_array.length;
@klandergren
klandergren / gist:1036958
Created June 21, 2011 00:27 — forked from gvinter/gist:1036932
Javascript Form
<form>
Name: <input type="textbox" name="name" /> <br />
Check box if you're alive: <input type="checkbox" name="alive" /> <br />
<input type="button" name="submit" value="we win click!" onClick="pulse(form)" />
</form>
<script type="text/javascript">
function pulse(data){
console.log(data);
@klandergren
klandergren / gist:1035005
Created June 20, 2011 01:42 — forked from gvinter/gist:1034982
Does alist contain x?
;; think on this:
;; contains-incomplete returns 0 if it doesn't find
;; the val and greater than 0 if it does
(define (contains-incomplete val list)
(fold-left (lambda (a x) (YOUR CODE) 0 list))
;; testing
(contains-incomplete 0 '(1 2 3)) ;; => 0
(contains-incomplete 1 '(1 2 3)) ;; => 1
@klandergren
klandergren / sicp_2.2.scm
Created June 17, 2011 18:34 — forked from gvinter/gist:1029936
SICP Exercise 2.2
;; 2.2
;; SICP Exercise 2.2
;; takes x and y coordinates to create a point
(define (make-point x y)
(cons x y))
(define (make-segment x1 y1 x2 y2)
;; needs implementation
)
@klandergren
klandergren / sicp2.17.scm
Created June 16, 2011 15:03 — forked from gvinter/sicp2.17.scm
SunnyCloud: 2.17 and 2.18
;; 2.17
;; Helpful link on equivalence
;; http://sicp.ai.mit.edu/Fall-2003/manuals/scheme-7.5.5/doc/scheme_4.html
(define (last-pair list)
(if (null? (cdr list))
(car list) ;; fixed paren error
(last-pair (cdr list))))