-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dc1083
commit 2fa9aae
Showing
28 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Just the Facts, ma'am. Factoria;s, this is. Write a function factorial(num) that, given a number, returns the product (multiplication) of all positive integers from 1 up to number (inclusive). FOr example, facotiral(3) = 6(or 1 * 2 * 3); factorial(5) = 120 (or 1 * 2 * 3 * 4 * 5). | ||
|
||
function factorial(num){ | ||
var val = 1; | ||
var i = 2; | ||
while(i <= num){ | ||
val *= i | ||
i++; | ||
} | ||
console.log(val); | ||
} | ||
|
||
factorial(1); | ||
factorial(2); | ||
factorial(3); | ||
factorial(5); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Implement function sigma(num) that given a number, returns the sum of all positive integers up to number (inclusive). Ex.: signma(3) = 6 (or 1 + 2 + 3); sigma(5) = 15 (or 1 + 2 + 3 + 4 + 5). | ||
|
||
function sigma(num){ | ||
var value = 0; | ||
var i = 1; | ||
while(i <= num){ | ||
value += i | ||
i++; | ||
} | ||
console.log(value); | ||
} | ||
|
||
sigma(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* Assume that you have a text field that is exactly 75 characters long. You want to fill it with spaces and astericks ('*'), sometimes called stars. You should print the given numbers of astericks consecutively. Depending on which function is called, those stars should be left-justified (first star would be very first char in the text field), or right-justified (last star would be very last char in the text field, with potentially some number of spaces at beginning of text field before the block of stars start), or centered in the 75-character text field (with same number of spaces on either side of the block of stars, plus/minus one). | ||
* write a function drawLeftStars(num) that accepts a number and prints that many astericks. | ||
* write a function drawRightStars(num) that prints 75 characters total. Stars should build from right side. That num characters should be astericks, the other 75 should be spaces. | ||
* write a function drawCenteredStars(num) that prints 75 characters total. Stars should be centered in the 75. The middle num characters should be astericks; the rest of the 75 spaces. | ||
*/ | ||
|
||
function drawLeftStars(num, char){ | ||
if(num <= char){ | ||
var diff = char - num; | ||
var symbols = ""; | ||
for ( var i = 1; i <= num; i++){ | ||
symbols += "*"; | ||
} | ||
for (var idx = 1; idx <= diff; idx++){ | ||
symbols += " "; | ||
} | ||
console.log(symbols); | ||
} | ||
else{ | ||
console.log("num exceeds char") | ||
} | ||
|
||
} | ||
drawLeftStars(4, 5); | ||
|
||
function drawRightStars(num, char){ | ||
if(num <= char){ | ||
var diff = char - num; | ||
var symbols = ""; | ||
for ( var i = 1; i <= num; i++){ | ||
symbols += "-"; | ||
} | ||
for (var idx = 1; idx <= diff; idx++){ | ||
symbols += "*"; | ||
} | ||
console.log(symbols); | ||
} | ||
else{ | ||
console.log("num exceeds char") | ||
} | ||
|
||
} | ||
drawRightStars(4,5); | ||
|
||
function drawCenteredStars(num, char){ | ||
if(num <= char){ | ||
var symbols = ""; | ||
var side = ((char - num)/2); | ||
for (var i = 1; i <= char; i++){ | ||
if(i <= side){ | ||
symbols += "-"; | ||
} | ||
else if(i > side && i <= num+side){ | ||
symbols += "*"; | ||
} | ||
else if(i > num+side){ | ||
symbols += "-"; | ||
} | ||
} | ||
console.log(symbols); | ||
} | ||
} | ||
|
||
drawCenteredStars(5, 75); |