Skip to content

Instantly share code, notes, and snippets.

View danieldunderfelt's full-sized avatar

Daniel Dunderfelt danieldunderfelt

View GitHub Profile
@danieldunderfelt
danieldunderfelt / randomArray.js
Created December 3, 2014 12:21
Generate an array with a random length, with distinct random values.
/**
*
* Usage: generateArray(10)
* Where 10 is the maximum allowed length (and value range) of the array.
*
* Example output: [5, 3, 9, 1, 0, 2]
*
*
*/
@danieldunderfelt
danieldunderfelt / compare.js
Last active August 29, 2015 14:01
Compare keys and values of two objects
/**
* Use this to compare one object's properties to corresponding properties on another object.
* Returns true if b contains all of the properties of a with the same values. Object b
* can contain more properties than object a, the important thing is that the values
* and property names of a are found on b. Enumerable properties only!
*/
function compare(a, b) {
var isEqual = [];
var keys = Object.keys(a);
@danieldunderfelt
danieldunderfelt / jquery.toggletext.js
Created January 17, 2014 11:52
Quick and dirty jQuery plugin to toggle an element's text between two alternatives.
/*
* Author: Daniel Dunderfelt
*
* Use: $(element).toggleText("text alternative 1", "text alternative 2");
*/
(function($) {
$.fn.extend({
toggleText: function(toggle1, toggle2) {
return this.each(function(i, ele) {