Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added exercises/concepts/problems.js
Empty file.
Empty file added exercises/concepts/solutions.js
Empty file.
50 changes: 46 additions & 4 deletions exercises/problems.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ See how many different ways you can write this function! There are a TON.
*/

function toString(b){
if (b==true){
return 'true';
} else return 'false';

}

function booleantoString(value){
if (value) {
return 'true';
} else return 'false';
}

function toString(b){
return b ? 'true' : 'false';
}

function booleanToString(b){
return b.toString();
}

function toString(b){
String(b)
}
-----------------------------------------------------------

Expand All @@ -12,7 +34,13 @@ Write a function called checkCoupon to verify that a coupon is valid and not exp
*/

function checkCoupon(enteredCode, correctCode, currentDate, expirationDate){
var current = Date.parse(currentDate);
var exp = Date.parse(expirationDate);

if (enteredCode == correctCode) && (exp > current){
return true;
}
return false;
}


Expand All @@ -21,8 +49,12 @@ function checkCoupon(enteredCode, correctCode, currentDate, expirationDate){
Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).
*/
function countSheeps(arrayOfSheep) {


var present = 0;
for (i=0; i<arrayOfSheep.length; i++){
if (arrayOfSheep[i]==true)
present++
}
return present;
}

-----------------------------------------------------------
Expand All @@ -44,8 +76,11 @@ SeriesSum(2) => 1 + 1/4 = "1.25"
SeriesSum(5) => 1 + 1/4 + 1/7 + 1/10 + 1/13 = "1.57"
*/
function SeriesSum(n) {


var sum =0;
for (i=0; i<n.length; i++){
sum += 1/(i*3 + 1)
}
return sum;
}

-----------------------------------------------------------
Expand All @@ -62,7 +97,11 @@ Write a function that returns the number of years 'Y' as a whole in order for Mr
Assumptions : Assume that Desired Principal 'D' is always greater than the initial principal, however it is best to take into consideration that if the Desired Principal 'D' is equal to Principal 'P' this should return 0 Years.
*/

function calculateYears(principal, interest, tax, desired) {



}
-----------------------------------------------------------

5. /*
Expand All @@ -83,7 +122,10 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
http://www.w3schools.com/jsref/jsref_parseint.asp
*/

function descendingOrder(n){


}
-----------------------------------------------------------

6. /*
Expand Down
55 changes: 54 additions & 1 deletion exercises/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
Write a function that takes a boolean value and turns it to the string equivilent.
See how many different ways you can write this function! There are a TON.
*/
dsaf
ads
fads
f


asdf
asd
f
asdf
asdf


asdfasdf
function booleanToString(b){
if (b===true){
return "true";
Expand Down Expand Up @@ -105,7 +119,7 @@ SeriesSum(5) => 1 + 1/4 + 1/7 + 1/10 + 1/13 = "1.57"

function SeriesSum(n) {
var sum = 0;
/ the sum starts out as being zero and everytime the loop completes, the value of sum is RETAINED and REUSED
// the sum starts out as being zero and everytime the loop completes, the value of sum is RETAINED and REUSED
for(var i = 0; i < n; i++) {
sum += 1 / (3 * i + 1);
//sum = sum (of previous loop) + 1(which is always the numerator in this example)/(3*i) + 1
Expand Down Expand Up @@ -974,3 +988,42 @@ function findOdd(arr) {

// VARIATION USING WTF ES6 BLOWING MY MIND RN
const findOdd = (xs) => xs.reduce((a, b) => a ^ b);

-----------------------------------------------------------

33. /*Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them.

a and b will both be positive integers, and a will always be the first number in the operation, and b always the second.

The four operators are "add", "subtract", "divide", "multiply".
*/

function arithmetic(a, b, operator){
switch(operator) {
case 'add':
return a + b;
case 'subtract':
return a - b;
case 'multiply':
return a * b;
case 'divide':
return a / b;
}
}

-----------------------------------------------------------

34. /*
Take 2 strings s1 and s2 including only letters from ato z.
Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.
*/

function longest(s1, s2) {
// your code
s3 = s1 + s2;
s4 = s3.split("");
s4 = s4.sort().filter(function(element, index, array){
return element !== array[index - 1];
});
return s4.join("");
}