Skip to content

Instantly share code, notes, and snippets.

View tsh-code's full-sized avatar

TSH code sharing tsh-code

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