This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arrangeArrayStructs(arrayToArrange, arrOrder, whichKey){ | |
var results = []; | |
arrOrder.forEach( function(item){ | |
results.push( arrayToArrange.filter( record => record[whichKey] == item ) ); | |
}); | |
return results; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* .unique() - filters out any duplicated values from an Array | |
* test = ["A", "B", "A", "C", "A", "C", "D"]; // given this | |
* test.unique(); // using this | |
* (4) ["A", "B", "C", "D"] // returns that | |
*/ | |
if (typeof Array.prototype.unique === "undefined"){ | |
Array.prototype.unique = function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// bind GA send to window.onerror event | |
window.onerror = function(message, source, lineno, colno, error){ | |
// find out if Google Analytics is present | |
if ( (typeof window[window.GoogleAnalyticsObject] !== "undefined") && (window[window.GoogleAnalyticsObject].answer === 42) ){ | |
// create a reference to the GoogleAnalyticsObject | |
tmpGA = window[window.GoogleAnalyticsObject]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* quick and dirty way to compare two objects in JS for equivalency */ | |
function compareObject(objFirst, objSecond){ | |
return ( JSON.stringify(objFirst) === JSON.stringify(objSecond) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Color(r,g,b){ | |
this.red = r; | |
this.green = g; | |
this.blue = b; | |
this.toHex = function (){ | |
var redHex = this.red.toString(16); | |
var greenHex = this.green.toString(16); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Book(title, author, genre, ISBN){ | |
this.title = title; | |
this.author = author; | |
this.genre = genre; | |
this.ISBN = ISBN; | |
} | |
function Library(){ | |
this.books = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* areAnagrams - compare two strings to see if they are anagrams | |
* | |
* param string1, first string to compare | |
* param string2, second string to compare | |
* return boolean, true = string are anagrams, false = strings are not | |
*/ | |
areAnagrams := method(string1, string2, | |
return ( lettersScore(string1) == lettersScore(string2) ) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* areAnagrams - tests if two strings are anagrams (e.g. ear, are) or not | |
* | |
* @param {String} string1 first string to compare (e.g. ear) | |
* @param {String} string2 second string to compare (e.g. are) | |
* @return {Boolean} true = anagrams, false = not anagrams | |
*/ | |
function areAnagrams(string1, string2){ | |
"use strict"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniqueChars := method(myString, | |
result := "" | |
myString foreach (i,v, | |
(i==myString findSeq(v asCharacter)) ifTrue(result = result .. v asCharacter) | |
) | |
return result | |
) | |