Skip to content

Instantly share code, notes, and snippets.

View mazyvan's full-sized avatar

Ivan E. Sanchez mazyvan

View GitHub Profile
@sjohnsonaz
sjohnsonaz / MergeSort.ts
Created October 23, 2016 17:42
Merge Sort in TypeScript
export default function MergeSort(items: number[]): number[] {
return divide(items);
}
function divide(items: number[]): number[] {
var halfLength = Math.ceil(items.length / 2);
var low = items.slice(0, halfLength);
var high = items.slice(halfLength);
if (halfLength > 1) {
low = divide(low);
@cybercase
cybercase / product.js
Last active February 10, 2023 10:59
Python-like itertools.product function in javascript
function product() {
var args = Array.prototype.slice.call(arguments); // makes array from arguments
return args.reduce(function tl (accumulator, value) {
var tmp = [];
accumulator.forEach(function (a0) {
value.forEach(function (a1) {
tmp.push(a0.concat(a1));
});
});
return tmp;
@crtr0
crtr0 / client.js
Created June 8, 2012 17:02
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});