Last active
April 29, 2021 15:21
-
-
Save skv-headless/6feb52078eb44a80736affbeb425c787 to your computer and use it in GitHub Desktop.
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 assert = require('assert'); | |
/** | |
* Calculates the circle's area for the given radius | |
* | |
* @param {number} radius | |
* @returns {number} cirle's area | |
*/ | |
function circleArea(radius) { | |
if (typeof radius === 'number') { | |
return Math.PI * radius * radius; | |
} | |
// NOTE: other option is to throw an error but it is unusual for js libraries | |
return 0; | |
} | |
assert.equal(circleArea(1), Math.PI); | |
assert.equal(circleArea(3), Math.PI * 9); | |
assert.equal(circleArea(null), 0); | |
assert.equal(circleArea(Infinity), Infinity); | |
assert.equal(circleArea(NaN), NaN); | |
/** | |
* Returns true if string's first letter is upper-cased, false otherwise. | |
* | |
* @param {string} string to test | |
* @returns {boolean} | |
*/ | |
function isFirstUpper(string) { | |
if (typeof string === 'string') { | |
return /[A-Z]/.test(string.charAt(0)); | |
} | |
return false; | |
} | |
assert.equal(isFirstUpper('Hello'), true); | |
assert.equal(isFirstUpper(''), false); | |
assert.equal(isFirstUpper(null), false); | |
assert.equal(isFirstUpper(1), false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment