This file contains hidden or 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 countChange (money,coins) { | |
| const arr = []; | |
| let sum; | |
| for(let i = 0; i < coins.length; i++) { | |
| for(let j = 0; j < coins.length; j++) { | |
| let value = coins[i] + coins[j]; | |
| //console.log(value, value, value); | |
| if(value === money) { | |
| arr.push(value); | |
| } |
This file contains hidden or 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
| /** | |
| Write a function that counts how many different ways you can make change for an amount of money, given an array of coin denominations. For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2: | |
| 1+1+1+1, 1+1+2, 2+2. | |
| The order of coins does not matter: | |
| 1+1+2 == 2+1+1 | |
| Also, assume that you have an infinite ammount of coins. | |
| Your function should take an amount to change and an array of unique denominations for the coins: |
This file contains hidden or 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
| //This returns true if the number is repeated | |
| function isRepeated(num) { | |
| let unique = []; | |
| let numArr = num.toString() | |
| .split(''); | |
| for (var i = 0; i < numArr.length; i++) { |
This file contains hidden or 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
| //There are a total of 6 challanges(3, 5, 7, 9, 11, 16) | |
| //challange 3 | |
| /* | |
| JavaScript | |
| Create a funtion called isIsogram that takes one argument, a word to test if it's an isogram. This function should return a boolean indicating whether it is an isogram (true) or not (false). | |
| Example: |
This file contains hidden or 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 power(a, b) { | |
| var result = 1; | |
| for (var i = 0; i < b; i++) { | |
| result = result * a; | |
| } | |
| return result; | |
| } |
This file contains hidden or 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
| let mySort = (nums) => { | |
| let sortNums = nums.sort( (a, b) => a - b ); | |
| let wholeNums = sortNums.map(num => Math.floor(num, -1)); | |
| let oddNums = wholeNums.filter(num => num % 2 == 1); | |
| let evenNums = wholeNums.filter(num => num % 2 == 0); | |
| let newNums = oddNums.concat(evenNums); | |
| return newNums; | |
| } | |
| mySort([90, 45, 66, 'bye', 100.5]); |
This file contains hidden or 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
| let removeDuplicates = (str) => { | |
| let regEx = /[^a-zA-Z]/g; | |
| str = str.replace(regEx, ""); | |
| let result = ''; | |
| let obj = { | |
| uniques: '', | |
| duplicates: 0 | |
| }; | |
| let count = 0; | |
This file contains hidden or 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
| /* Write a mySort function which takes in an array integers, and should return an array of the inputed integers sorted such that the odd numbers come first and even numbers come last. | |
| For exampl1e: | |
| mySort( [90, 45, 66, 'bye', 100.5] ) | |
| should return | |
| [45, 66, 90, 100] */let mySort = (nums) => { | |
| let sortNums = nums.sort( (a, b) => a - b ); | |
| let filterNums = sortNums.map(num => Math.floor(num)); | |
| let oddNums = []; | |
| let evenNums = []; |
This file contains hidden or 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
| class ShoppingCart { | |
| constructor(){ | |
| this.total = 0; | |
| this.items = { }; | |
| } | |
| addItem(itemName, quantity, price) { | |
| let cost = quantity * price; | |
| this.total = this.total + cost; | |
| this.items[itemName] = quantity; |
This file contains hidden or 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
| class ShoppingCart { | |
| constructor () { | |
| this._total = 0; | |
| this._item = {}; | |
| } | |
| addItem(itemName, quantity, price) { | |
| this._total += price; | |
| //confirm if you should use dot notation or bracket notation to access itemName. | |
| item.[itemName] = quantity; |