JSFiddle

  • JS: Extending Objects Function

    This function takes n number of objects (as arguments) and adds their properties to a single object.

    // create shorthand JavaScript function
    var $ = function(id) {
       return document.getElementById(id);
    };
    
    // extend function
    var extend = function(obj) {
       for (var i ...
  • JS: Fibonacci Sequence (using a for loop)

    Returning a number in the Fibonnaci sequence

    // create shorthand JavaScript
    var $ = function(id) {
       return document.getElementById(id);
    };
    
    // fibonacci sequence function
    var fib_iter = function(n) {
    
       if (n < 0 ...
  • JS: Word Counter

    This word counter app uses pure JavaScript to take a string as an argument, count each word in the string, and output how many times that word shows up in the string.

    // wordCounter function
    function wordCounter(string) {
    
    	// clean up the string from punctuations, white spaces and uppercase letters
       string = string.toLowerCase().replace ...
  • Underscore.js: Return Unique Values In Arrays

    This fiddle uses the _.uniq() function from Underscore.js.

    // create the _ variable (used in underscore.js)
    var _ = function(obj) {
        if (obj instanceof _) return obj;
        if (!(this ...
  • JS: Remove Duplicates #15 is the latest revision

    Takes an array as an argument and removes the duplicates.

    // removeDuplicates function
    function removeDuplicates(array) {
    
       // sort the array
       array.sort();
    
       // create the results array to put the non-duplicates in
       var ...