This file contains hidden or 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 isNull(v) { | |
return typeof v === "object" && !v; | |
} | |
function isPrimitive(v) { | |
return ["number", "string", "boolean", "undefined"].indexOf(typeof v) !== -1 || isNull(v); | |
} | |
function isPlainObject(o) { | |
return o && typeof o === "object" && o.constructor === Object; |
This file contains hidden or 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
/** | |
* Returns an array of all possible permutations of the given array provided the arrays length is smaller then 13 | |
* @param {Array} arr The given array to compute it's permutations. Empty array if not specified. | |
* @returns {Array} an array of all the possible permutations of arr | |
*/ | |
function perm(arr = []) { | |
if(arr.length > 12) { | |
// Javascript Array max length is 2^32 - 1 but 13! > 2^32 -1 | |
throw new RangeError("perm() allowed max array length is 12"); | |
} |
This file contains hidden or 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 curry(fn) { | |
var slice = Array.prototype.slice; | |
var arity = fn.length; | |
var args = slice.call(arguments, 1); | |
function acc() { | |
var largs = args; | |
if (arguments.length > 0) { | |
largs = largs.concat(slice.call(arguments, 0)); |
This file contains hidden or 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
package assignment13.stm; | |
import scala.concurrent.stm.Ref; | |
import scala.concurrent.stm.TArray; | |
import scala.concurrent.stm.japi.STM; | |
import java.util.concurrent.Callable; | |
/** | |
* This class implements a {@link assignment13.stm.CircularBuffer} using software-transactional memory (more |