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
fact(1) = 1 | |
fact(2) = 2 * fact(1) | |
fact(3) = 3 * fact(2) | |
fact(4) = 4 * fact(3) | |
fact(5) = 5 * fact(4) |
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
fact(1) = 1 | |
fact(2) = 2 * 1 | |
fact(3) = 3 * 2 * 1 | |
fact(4) = 4 * 3 * 2 * 1 | |
fact(5) = 5 * 4 * 3 * 2 * 1 |
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
fact(n) = n * fact(n - 1) |
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 fact (n) { | |
//Base Case | |
//Recrusive Case | |
//Code to be executed | |
} |
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 fact (n) { | |
if (n == 1) | |
return 1; | |
//Recrusive Case | |
//Code to be executed | |
} |
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 fact (n) { | |
if (n == 1) | |
return 1; | |
else | |
return n * fact(n - 1); | |
} |
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
if (numRows === 0) { | |
return []; | |
} | |
var triangle = [[1]]; | |
for(var i = 0; i < numRows - 1; i++ ) { | |
var row = [1]; | |
for(var j = 1; j < triangle[i].length; j++) { | |
row[j] = triangle[i][j] + triangle[i][j-1]; |
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 Node(val){ | |
this.value = val; | |
this.left = null; | |
this.right = null; | |
} | |
function BinaryTree(){ | |
this.root = null; | |
} |
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
/* Prompt: tackling floating-point imprecision with the CashAmount class | |
In programming languages such as JavaScript, 0.1 + 0.2 does not equal 0.3. This is true in Ruby, Python, etc. The imprecision is inherent in floating-point arithmetic, it isn't because JavaScript itself is wonky. | |
These tiny errors can add up and cause actual wrong answers over time if you're not careful. They also make it harder to unit-test your work, since you have to compare within ranges rather than comparing to exact expected values. | |
To deal with this specifically within a monetary context, let's make a class called CashAmount that accepts double values (e.g., 14.72) and will never suffer from the aforementioned precision problems. A CashAmount represents a collection of bills and coins, such as you might find in your wallet, purse, or a cash register. | |
Note: you can do this by converting to pennies for all denominations so you are always working with integers, then converting back to a two-decimal float as needed. */ |
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
//given "0-360" returns the nearest cardinal direction "N/NE/E/SE/S/SW/W/NW/N" | |
function getCardinal (angle) { | |
if (angle >= 0 && angle <= 22 || angle >= 338 && angle <= 360) | |
return "N"; | |
if (angle >= 23 && angle <= 67) | |
return "NE"; | |
if (angle >= 68 && angle <= 112) | |
return "E"; | |
if (angle >= 113 && angle <= 157) | |
return "SE"; |
OlderNewer