JSFiddle

  • Unstable vs. Stable Sorting #5 is the latest revision

    Showing how the Array.prototype.sort function is unstable, and how to make it stable. The results of the unstable sorting may vary from browser to browser. For example, Chrome 35's sort algorithm uses insertion sort (which is stable) for arrays shorter than 11 elements, and QuickSort for longer arrays (which is unstable); hence why an array with 11 elements is used in this fiddle.

    function unstableSort(a, b) {
        return a.x - b.x;
    }
    
    function stableSort(a, b) {
        if (a.x === b.x) {
            return indexed ...
  • ContentEditable and FireFox #8 is the latest revision

    Fiddle to show a bug(?) in FireFox.

    <h1 contenteditable="true">Copy this text here</h1>
    <p contenteditable="true">And then paste it into here - notice that in FF, a new h1 is added after ...</p>
  • SimpleId Conflict Test

    Testing conflicts when generating simpe ids.

    var SimpleId = (function() {
        var idLength = 10,
            idAlphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";   
    
        SimpleId = {
            generate: function(length, alphabet) {
                var id = [],
                    length = length || idLength,
                    alphabet = alphabet ...
  • Object Diff Generator

    Generates a diff between two objects

    var object1 = {
        x: 20,
        y: 30,
        moving: {
            x: 0,
            y: 50
        }
    };
    
    var object2 = {
        x: 20,
        y: 25,
        moving: {
            x: 0 ...
  • Ordinal Number Generator #6 is the latest revision

    Test for a function to create ordinal numbers from integers (1 => 1st, 2 => 2nd)

    Number.prototype.toOrdinal = function() {
         var s=["th","st","nd","rd"],
           v=this%100;
         return this+(s[(v-20)%10]||s[v ...
  • 1
  • 2