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
Array.prototype.makeObjectOn = function(prop) { | |
return this.reduce((acc, el, idx) => { | |
acc[el[prop] || idx] = el | |
return acc | |
}) | |
} |
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
/*********************************************************************************************************************** | |
* Partition an array into two arrays based on passing each element to a predicate function. | |
* | |
* This function is designed to extend the Array prototype, but only by the explicit action of the consuming library. | |
* E.G. Assuming the function below belongs to a "utils" module, you must write something like the following: | |
* | |
* const utils = require('./utils.js') | |
* Array.prototype.partitionWith = utils.partitionWith | |
* | |
* This function must be defined using a traditional "function" declaration instead of an arrow function. If an arrow |
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
const compose = fn1 => fn2 => val => fn2(fn1(val)) | |
// Remove only the start and end double quotes in a string | |
const stripQuotes = str => str.replace(/(^")|("$)/g,"") | |
// Remove commas that might occur inside names | |
const removeCommas = str => str.replace(/,/g,"") | |
const cleanTxt = compose(stripQuotes)(removeCommas) |
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
-module(beersong). | |
-export([sing/0]). | |
-define(LIMIT, 99). | |
-define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~nGo to the store and buy some more, 99 bottles of beer on the wall.~n"). | |
-define(TEMPLATE_N, "~s of beer on the wall, ~s of beer.~nTake one down and pass it around, ~s of beer on the wall.~n~n"). | |
print_verse(0) -> io:format(?TEMPLATE_0, phrase(0)); | |
print_verse(Bottle) -> io:format(?TEMPLATE_N, phrase(Bottle)). | |
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
div_result(DIV(EIGHT)(FIVE)); // -> {isPos: true, quot : 1, rem : 3} | |
div_result(DIV(MINUS_EIGHT)(FIVE)); // -> {isPos: false, quot : 1, rem : 3} | |
div_result(DIV(EIGHT)(MINUS_FIVE)); // -> {isPos: false, quot : 1, rem : 3} | |
div_result(DIV(MINUS_EIGHT)(MINUS_FIVE)); // -> {isPos: true, quot : 1, rem : 3} |
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
// Helper functions to reify the NUMBER function returned by DIV | |
var magnitude_quot = numFn => magnitude(HEAD(TAIL(numFn))); | |
var magnitude_rem = numFn => magnitude(TAIL(TAIL(numFn))); | |
var div_result = numFn => | |
({ isPos : sign(numFn), | |
quot : magnitude_quot(numFn), | |
rem : magnitude_rem(numFn) | |
}); |
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
var DIV = dividend => divisor => | |
NUMBER(NOT(XOR(SIGN(dividend)) | |
(SIGN(divisor)))) | |
(Y(do_div_magnitudes) | |
(ZERO_MAGNITUDE) | |
(PAIR(ABS(dividend))(ABS(divisor)))); |
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
var DIV = val1 => val2 => Y(do_div)(ZERO)(PAIR(val1)(val2)); |
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
var IS_MAGNITUDE_LTE = | |
qtyFn1 => | |
qtyFn2 => | |
IS_ZERO_MAGNITUDE(SUBTRACT_MAGNITUDES(qtyFn1)(qtyFn2)); | |
var do_div_magnitudes = | |
div_next => | |
count => | |
pair => | |
// Inner 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
var DIV = val1 => val2 => Y(do_div)(ZERO)(PAIR(val1)(val2)); |
NewerOlder