Skip to content

Instantly share code, notes, and snippets.

@paullewis
paullewis / requestIdleCallback.js
Last active Apr 9, 2021
Shims rIC in case a browser doesn't support it.
View requestIdleCallback.js
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@paullewis
paullewis / gist:1982121
Created Mar 5, 2012
Mergesort in JavaScript
View gist:1982121
/**
* An implementation for Mergesort. Less efficient
* than Quicksort. Again, you'd just use Array.sort
* but if you found yourself unable to use that
* there's always this option.
*
* Tests with:
*
* var array = [];
* for(var i = 0; i < 20; i++) {
@paullewis
paullewis / gist:1981455
Created Mar 5, 2012
Quicksort in JavaScript
View gist:1981455
/**
* An implementation for Quicksort. Doesn't
* perform as well as the native Array.sort
* and also runs the risk of a stack overflow
*
* Tests with:
*
* var array = [];
* for(var i = 0; i < 20; i++) {
* array.push(Math.round(Math.random() * 100));
@paullewis
paullewis / gist:1973769
Created Mar 4, 2012
Heap in JavaScript
View gist:1973769
/*
* Can be tested with the following:
*
* var heap = new AEROTWIST.Heap();
*
* for(var i = 10; i > 0; i--) {
* heap.add(Math.round(Math.random() * 100));
* }
*
* for(var i = 10; i > 0; i--) {