View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

james anderson


Writing Code (1 point):

fib := [:n| (((1.6180339 raisedTo: n) - ((0 - 0.6180339) raisedTo: n))/2.236067977) ceiling].

(had to do something at least a little different..)

Tracing Code (1 point)
1: | data onlyPositiveNumbers |
2: data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).
3: onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].
4: data := data select: onlyPositiveNumbers.
5: data := data copyUpTo: 999. "not including"
6: Transcript show: data average

1) declares local variables and here data is set to nil.
2) an ordered collection is instantiated and stored in data, using the given initial values
3) creates a lambda which returns true only for positive numbers.
4) data is filtered with the lambda (similar to a map in lisp); result is saved, so data = (1 2 3 6 999 2)
5) elements up to but not including 999 are selected from data and the result is saved, so data = (1 2 3 6 2)
6: the data collection is passed the average msg and returns the average,which is output to the transcript.

Link to this Page