diff --git a/01-make-change/change-Tyler.js b/01-make-change/change-Tyler.js new file mode 100644 index 0000000..54f9cef --- /dev/null +++ b/01-make-change/change-Tyler.js @@ -0,0 +1,16 @@ +function change(n){ + // coinValues set to [quarters, dimes, nickels, pennies] + const coinValues = [25,10,5,1]; + //amount of [quarters, dimes, nickels, pennies] pushed into array + let coins = []; + + for(let i = 0; i < coinValues.length; i++){ + if(n >= coinValues[i]){ + coins[i] = Math.floor(n / coinValues[i]); + n %= coinValues[i]; + } else { + coins[i] = 0; + } + } + return coins; +} diff --git a/01-make-change/change.js b/01-make-change/change.js new file mode 100644 index 0000000..cab4652 --- /dev/null +++ b/01-make-change/change.js @@ -0,0 +1,31 @@ +let coins = []; +function change(n){ + coins=[0,0,0,0]; + while(n!=0){ + if (n>=25){ + const di = Math.floor(n/25); + coins[0] = di; + n = n % 25; + } + else if (n>=10){ + const di = Math.floor(n/10); + coins[1] = di; + n = n % 10; + } + else if (n>=5){ + const di = Math.floor(n/5); + coins[2] = di; + n = n % 5; + } + else if (n>=1){ + const di = Math.floor(n/1); + coins[3] = di; + n = n % 1; + } + } + console.log(coins); + } + +console.log(change(34)); +console.log(change(78)); +console.log(change(21)); diff --git a/01-make-change/laurens-change.js b/01-make-change/laurens-change.js new file mode 100644 index 0000000..a71e8e4 --- /dev/null +++ b/01-make-change/laurens-change.js @@ -0,0 +1,17 @@ +//takes two inputs, the amount of money that needs to be made into change +//and an array listing the value of each coin +//will work with different values in case you need to know +//how many silver sickles, bronze knuts, or golden galleons to make change with ;) + +function change(change, coins) { + var returnedChange = 0; + var coinCount = []; + coins.forEach(function(coin){ + var newChange = change - returnedChange; + var coinAmount = Math.floor(newChange / coin); + coinCount.push(coinAmount); + returnedChange += coinAmount * coin; + }); + console.log(coinCount); + return coinCount; +} \ No newline at end of file diff --git a/02-ace-of-some-base/recursion-es6.js b/02-ace-of-some-base/recursion-es6.js new file mode 100644 index 0000000..eb92aab --- /dev/null +++ b/02-ace-of-some-base/recursion-es6.js @@ -0,0 +1,9 @@ +const isPalindrome = s => s.toString() === s .toString() .split('') .reverse() .join(''); +const ariseMyBase = (predicate, base) => num => + predicate(num.toString(base)) || base >= 36 + ? base + : ariseMyBase(predicate, ++base, num); + +const palindromeBase = ariseMyBase(isPalindrome, 2); + +console.log(palindromeBase(11)) // 20 diff --git a/03-lowest-missing-number-in-noncontigous-sequence/README.md b/03-lowest-missing-number-in-noncontigous-sequence/README.md new file mode 100644 index 0000000..ccceea8 --- /dev/null +++ b/03-lowest-missing-number-in-noncontigous-sequence/README.md @@ -0,0 +1,18 @@ +# MissingNo + +Given an array of integers, find the first missing positive integer. In other +words, find the lowest positive integer that does not exist in the array. The +array can contain duplicates and negative numbers as well. + +## Input +`number` - Array of numbers + +## Output +the Lowest missing number + +## Example + +``` +missingNo([3, 4, -1, 1]) // 2 +missingNo([1,2,0,-1]) // 3 +``` diff --git a/03-lowest-missing-number-in-noncontigous-sequence/es6-reduce.js b/03-lowest-missing-number-in-noncontigous-sequence/es6-reduce.js new file mode 100644 index 0000000..40bf0ec --- /dev/null +++ b/03-lowest-missing-number-in-noncontigous-sequence/es6-reduce.js @@ -0,0 +1,6 @@ +// run with node es6-reduce.js + +const missingNo = l => l.concat().sort((a,b)=>a-b).reduce((m,v,i) => v===m ? m+1 : m ,1); + +console.log(missingNo([4,6,7,8,1,2,2,2,4,-1,-2,8,3])); // 5 +console.log(missingNo([4,6,7,8,1,2,2,2,4,-1,-2,8])); // 3