From a4d1557c3ee1a34fbfb6e8917ff665c0c275b8fd Mon Sep 17 00:00:00 2001 From: Stephanie Workman Date: Mon, 27 Mar 2017 18:21:26 -0500 Subject: [PATCH] added comments --- exercises/concepts/problems.js | 0 exercises/concepts/solutions.js | 0 exercises/problems.js | 50 +++++++++++++++++++++++++++--- exercises/solutions.js | 55 ++++++++++++++++++++++++++++++++- 4 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 exercises/concepts/problems.js create mode 100644 exercises/concepts/solutions.js diff --git a/exercises/concepts/problems.js b/exercises/concepts/problems.js new file mode 100644 index 0000000..e69de29 diff --git a/exercises/concepts/solutions.js b/exercises/concepts/solutions.js new file mode 100644 index 0000000..e69de29 diff --git a/exercises/problems.js b/exercises/problems.js index 5ee17e3..4840c21 100644 --- a/exercises/problems.js +++ b/exercises/problems.js @@ -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) } ----------------------------------------------------------- @@ -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; } @@ -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 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 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 @@ -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(""); +}