This file contains hidden or 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
| var Human = function(name){ | |
| this.name = name; | |
| this.isAlive = true; | |
| this.energy = 1; | |
| }; | |
| Human.prototype.eat = function() { | |
| return this.energy++; | |
| }; | |
This file contains hidden or 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
| /** | |
| * class.js | |
| * @author Dmitry A. Soshnikov | |
| */ | |
| function Class(params) { | |
| /** | |
| * Constructor function | |
| * If not specified, use default |
This file contains hidden or 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
| function addEvent(elem, evType, fn, useCapture) { | |
| if(elem.addEventListener) { | |
| return elem.addEventListener(evType, fn, useCapture); | |
| } else if(elem.attachEvent){ | |
| var r = elem.attachEvent('on'+evType,fn); | |
| return r; | |
| } else { | |
| elem['on'+evType] = fn; | |
| } | |
| } |
This file contains hidden or 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
| $extend = function(subClass,superClass) { | |
| function F() {}; | |
| F.prototype = superClass.prototype; | |
| subClass.prototype = new F(); | |
| subClass.prototype.constructor = subClass; | |
| subClass._base = superClass; | |
| subClass._super = superClass.prototype; | |
| }; | |
This file contains hidden or 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
| #inherit.py | |
| class SchoolMember: | |
| '''Represents any school member''' | |
| def __init__(self, name, age): | |
| self.name = name | |
| self.age = age | |
| print 'Initialized SchoolMember constructor: %s' % self.name |
This file contains hidden or 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
| ''' | |
| Merging two arrays or three..or four..or five..or ...n :P | |
| by Adrian Statescu <adrian@thinkphp.ro> | |
| MIT Style License | |
| ''' | |
| import merge | |
| l = ([2,4,6,8],[1,3,5,7,9],[11,12,13,14,15,16,17]) | |
| i = 1; | |
| ll = l[0] |
This file contains hidden or 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
| ''' | |
| by Adrian Statescu <adrian@thinkphp.ro> | |
| MIT Style License | |
| ''' | |
| def merge(arrA,arrB): | |
| arrC = [] | |
| i = 0 | |
| j = 0 | |
| n = len(arrA)-1 | |
| m = len(arrB)-1 |
This file contains hidden or 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
| /** | |
| * Breadth-First Traversal of a Binary Tree in PHP | |
| * by Adrian Statescu <adrian@thinkphp.ro> | |
| * MIT Style License | |
| */ | |
| class Node { | |
| public $info; | |
| public $left; | |
| public $right; |
This file contains hidden or 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
| ''' | |
| Breadth-First Traversal of a Binary Tree in Python | |
| by Adrian Statescu <adrian@thinkphp.ro> | |
| MIT Style License | |
| Given a tree (binary tree), prints all it's elements by level (breadth first traversal) | |
| 9 | |
| 2 4 |
This file contains hidden or 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
| /** | |
| * Breadth-First Traversal of a Binary Tree in JS | |
| * by Adrian Statescu <adrian@thinkphp.ro> | |
| * MIT Style License | |
| */ | |
| function Node(info){ | |
| this.info = info | |
| this.left = null; |