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
| const nullFn = (fn) => typeof fn === 'function' ? fn : () => null; | |
| function dict(key, value, struct) { | |
| return (function (localStruct) { | |
| return (ref) => ref === key ? value : localStruct(ref) | |
| })(nullFn(struct)); | |
| } | |
| function memoize(fn) { | |
| let store = null; |
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
| const multiply = (a, b) => a * b; | |
| const divide = (a, b) => a / b; | |
| const multiplyThenDivide = (a, b, c) => divide(multiply(a, b), c); |
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
| describe('runMultiplyThenDivide', function() { | |
| it('should properly evaluate the composition of multiply and divide', function () { | |
| const specSet = [ | |
| { | |
| name: 'Zero-multiplication', | |
| setupValues: { a: 0, b: 1, c: 2 }, | |
| expectedValue: 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
| describe('multiplyThenDivide', function() { | |
| it('should return 0 when multiplying by 0, dividing by 2', function() { | |
| assert.equal(multiplyThenDivide(0, 1, 2), 0); | |
| }); | |
| it('should return half of value when multiplying by 5, dividing by 2', function() { | |
| assert.equal(multiplyThenDivide(1, 5, 2), 2.5); | |
| }); |
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
| { | |
| "Mocha describe": { | |
| "prefix": "mdesc", | |
| "body": [ | |
| "describe('$1', function () {", | |
| "\t$2", | |
| "});" | |
| ], |
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 (testRunner) { | |
| 'use strict'; | |
| function logAndTestUi(sample, expectedMean, expectedStandardDeviation) { | |
| var message = 'Testing -- ' + | |
| 'sample: ' + JSON.stringify(sample) + '; ' + | |
| 'expected mean: ' + expectedMean + '; ' + | |
| 'expected standard deviation: ' + expectedStandardDeviation; | |
| console.log(message); |
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
| var testRunner = (function () { | |
| 'use strict'; | |
| function isMatch (expectedValue, actualValue) { | |
| var equalMatch = expectedValue === actualValue; | |
| var NaNMatch = Number.isNaN(expectedValue) && Number.isNaN(actualValue); | |
| return equalMatch || NaNMatch; | |
| } | |
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
| <html> | |
| <body> | |
| <input type="text" value="" name="sample" id="sample" /> | |
| <button id="compute">Compute Mean and Standard Deviation</button> | |
| <h4>Mean:</h4> | |
| <p id="mean">0</p> | |
| <h4>Standard Deviation:</h4> |
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
| var viewHelper = (function () { | |
| 'use strict'; | |
| function parseNumberValues (valueStr) { | |
| return valueStr.trim().split(/[\s\,]+/).map(parseFloat); | |
| } | |
| return { | |
| parseNumberValues: parseNumberValues | |
| }; |
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
| var statsApi = (function () { | |
| 'use strict'; | |
| var square = pow(2); | |
| var squareRoot = pow(0.5); | |
| function getStandardDeviation (values) { | |
| var xBar = getMean(values); | |
| var computedValues = values.map(subtractMeanAndSquare(xBar)); | |
| return squareRoot(getMean(computedValues)); |