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 Dog(name) { | |
| this.name = name; | |
| } | |
| Dog.prototype.bark = function() { | |
| console.log(this.name + ': Woof! Woof!'); | |
| }; |
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 median(values) { | |
| var values = values.sort( function(a,b) {return a - b;} ); | |
| var half = Math.floor(values.length/2); | |
| if(values.length % 2) | |
| return values[half]; | |
| else | |
| return (values[half-1] + values[half]) / 2.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
| var data = [2, 1, 3, 7, 2, 4, 0, 5]; | |
| console.log(getLast(data)); | |
| console.log(median(data)); |
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 getLast(values) { | |
| return values[values.length - 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
| var data = [2, 1, 3, 7, 2, 4, 0, 5]; | |
| console.log(getLast(data)); | |
| console.log(median(data)); |
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 data = [2, 1, 3, 7, 2, 4, 0, 5]; | |
| console.log(median(data)); | |
| console.log(getLast(data)); |
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 values = values.sort( function(a,b) {return a - b;} ); |
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 sort(values, callback) { | |
| return values.slice().sort(callback); | |
| } | |
| function median(values) { | |
| var values = sort(values, function(a,b) {return a - b;} ); | |
| var half = Math.floor(values.length/2); |
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
| console.log(median(data)); // 2.5 | |
| console.log(getLast(data)); // 7 | |
| console.log(getLast(data)); // 7 | |
| console.log(median(data)); // 2.5 |
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 tokenExpired(token) { | |
| return token.expirationDate < new Date(); | |
| } |
OlderNewer