-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2015-01-14 http://www.ipreferjim.com/?p=1209
- Loading branch information
1 parent
e70ff75
commit 7422240
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Animal{ | ||
constructor(legs) { | ||
switch (legs) { | ||
case 2: | ||
this.locomotion = 'bipedal'; | ||
break; | ||
case 4: | ||
this.locomotion = 'quadrapedal'; | ||
default: | ||
} | ||
} | ||
move() { | ||
process.stdout.writeln("I'm a %j animal!", this.locomotion); | ||
} | ||
static getTypeName() { | ||
return "Animal"; | ||
} | ||
} | ||
|
||
class Bird extends Animal { | ||
constructor(){ | ||
super(2); | ||
} | ||
} | ||
|
||
class Lion extends Animal { | ||
constructor(){ | ||
super(4); | ||
} | ||
} | ||
|
||
var bird = new Bird(); | ||
bird.move(); | ||
|
||
var lion = new Lion(); | ||
lion.move(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var fibonacci = { }; | ||
fibonacci[Symbol.iterator] = function*() { | ||
var pre = 0, cur = 1; | ||
for (;;) { | ||
var temp = pre; | ||
pre = cur; | ||
cur += temp; | ||
yield cur; | ||
} | ||
} | ||
|
||
for (var n of fibonacci) { | ||
// truncate the sequence at 1000 | ||
if (n > 1000) { | ||
break; | ||
} | ||
process.stdout.write(n + '\n'); | ||
} |