Skip to content
Browse files

add

  • Loading branch information...
1 parent 050fe02 commit 85412f916abccf4e655c34bfe8822d8e3b8cbfcb @zdwalter committed
Showing with 51 additions and 1 deletion.
  1. +1 −1 public/javascripts/debug.js
  2. +28 −0 public/javascripts/mit/OOP 1.js
  3. +22 −0 public/javascripts/mit/summation.js
View
2 public/javascripts/debug.js
@@ -221,7 +221,7 @@ _f();
catch(e) {
Debug.setListener(null);
_exit = true;
- var exception = {"event":"uncaught_exception","exception_msg":e.toString(), stdout: _stdout};
+ var exception = {"event":"uncaught_exception","exception_msg":e.toString().replace(/\/\/USER_SCRIPT/g,''), stdout: _stdout};
_print(JSON.stringify(exception));
}
// Get rid of the debug event listener.
View
28 public/javascripts/mit/OOP 1.js
@@ -0,0 +1,28 @@
+// Object-oriented programming intro
+// Adapted from MIT 6.01 course notes (Section 3.5)
+// http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf
+
+function Staff601() {
+ this.course = '6.01'
+ this.building = 34
+ this.room = 501
+}
+
+Staff601.prototype.salutation = function(self) {
+ if (typeof self === 'undefined') self = this;
+ return self.role + ' ' + self.name
+}
+
+pat = new Staff601()
+print(pat.course)
+
+pat.name = 'Pat'
+pat.age = 60
+pat.role = 'Professor'
+
+print(pat.building)
+pat.building = 32
+print(pat.building)
+
+print(pat.salutation())
+print(Staff601.prototype.salutation(pat))
View
22 public/javascripts/mit/summation.js
@@ -0,0 +1,22 @@
+// Higher-order functions
+// Adapted from MIT 6.01 course notes (Section A.2.2)
+// http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf
+
+function summation(low, high, f, next) {
+ s = 0
+ x = low
+ while (x <= high) {
+ s = s + f(x)
+ x = next(x)
+ }
+ return s
+}
+
+function sumsquares(low, high) {
+ return summation(low, high,
+ function(x) { return x*x},
+ function(x) { return x+1})
+}
+
+print(sumsquares(1, 10))
+

0 comments on commit 85412f9

Please sign in to comment.
Something went wrong with that request. Please try again.