-
Notifications
You must be signed in to change notification settings - Fork 137
Completed Projects w/ Matt Jackson #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b747cab
702bfc7
f040d2b
04cca0e
5293eba
d73f8b0
dfd17e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,137 +3,180 @@ | |
| const multiplyByTen = (num) => { | ||
| // return num after multiplying it by ten | ||
| // code here | ||
| return num * 10; | ||
| }; | ||
|
|
||
| const subtractFive = (num) => { | ||
| // return num after subtracting five | ||
| // code here | ||
| return num - 5; | ||
| }; | ||
|
|
||
| const areSameLength = (str1, str2) => { | ||
| // return true if the two strings have the same length | ||
| // otherwise return false | ||
| // code here | ||
| if (str1.length === str2.length) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whenever you have an if statement for returning
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expression is automatically simplified to either a |
||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const areEqual = (x, y) => { | ||
| // return true if x and y are the same | ||
| // otherwise return false | ||
| // code here | ||
| if (x === y) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, just do |
||
| return true; | ||
| } | ||
| return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole function could be simplified to: |
||
| }; | ||
|
|
||
| const lessThanNinety = (num) => { | ||
| // return true if num is less than ninety | ||
| // otherwise return false | ||
| // code here | ||
| if (num < 90) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const greaterThanFifty = (num) => { | ||
| // return true if num is greater than fifty | ||
| // otherwise return false | ||
| // code here | ||
| if (num > 50) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const add = (x, y) => { | ||
| // add x and y together and return the value | ||
| // code here | ||
| return x + y; | ||
| }; | ||
|
|
||
| const subtract = (x, y) => { | ||
| // subtract y from x and return the value | ||
| // code here | ||
| return x - y; | ||
| }; | ||
|
|
||
| const divide = (x, y) => { | ||
| // divide x by y and return the value | ||
| // code here | ||
| return x / y; | ||
| }; | ||
|
|
||
| const multiply = (x, y) => { | ||
| // multiply x by y and return the value | ||
| // code here | ||
| return x * y; | ||
| }; | ||
|
|
||
| const getRemainder = (x, y) => { | ||
| // return the remainder from dividing x by y | ||
| // code here | ||
| return x % y; | ||
| }; | ||
|
|
||
| const isEven = (num) => { | ||
| // return true if num is even | ||
| // otherwise return false | ||
| // code here | ||
| if (num % 2 === 0) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const isOdd = (num) => { | ||
| // return true if num is odd | ||
| // otherwise return false | ||
| // code here | ||
| if (num % 2 !== 0) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const square = (num) => { | ||
| // square num and return the new value | ||
| // code here | ||
| return Math.pow(num, 2); | ||
| }; | ||
|
|
||
| const cube = (num) => { | ||
| // cube num and return the new value | ||
| // code here | ||
| return Math.pow(num, 3); | ||
| }; | ||
|
|
||
| const raiseToPower = (num, exponent) => { | ||
| // raise num to whatever power is passed in as exponent | ||
| // code here | ||
| return Math.pow(num, exponent); | ||
| }; | ||
|
|
||
| const roundNumber = (num) => { | ||
| // round num and return it | ||
| // code here | ||
| return Math.round(num); | ||
| }; | ||
|
|
||
| const roundUp = (num) => { | ||
| // round num up and return it | ||
| // code here | ||
| return Math.ceil(num); | ||
| }; | ||
|
|
||
| const addExclamationPoint = (str) => { | ||
| // add an exclamation point to the end of str and return the new string | ||
| // 'hello world' -> 'hello world!' | ||
| // code here | ||
| return `${str}!`; | ||
| }; | ||
|
|
||
| const combineNames = (firstName, lastName) => { | ||
| // return firstName and lastName combined as one string and separated by a space. | ||
| // 'Lambda', 'School' -> 'Lambda School' | ||
| // code here | ||
| return `${firstName} ${lastName}`; | ||
| }; | ||
|
|
||
| const getGreeting = (name) => { | ||
| // Take the name string and concatenate other strings onto it so it takes the following form: | ||
| // 'Sam' -> 'Hello Sam!' | ||
| // code here | ||
| return `Hello ${name}!`; | ||
| }; | ||
|
|
||
| // If you can't remember these area formulas then head over to Google or look at the test code. | ||
|
|
||
| const getRectangleArea = (length, width) => { | ||
| // return the area of the rectangle by using length and width | ||
| // code here | ||
| return length * width; | ||
| }; | ||
|
|
||
| const getTriangleArea = (base, height) => { | ||
| // return the area of the triangle by using base and height | ||
| // code here | ||
| return (base * height) / 2; | ||
| }; | ||
|
|
||
| const getCircleArea = (radius) => { | ||
| // return the rounded area of the circle given the radius | ||
| // code here | ||
| return Math.round(Math.PI * Math.pow(radius, 2)); | ||
| }; | ||
|
|
||
| const getRectangularPrismVolume = (length, width, height) => { | ||
| // return the volume of the 3D rectangular prism given the length, width, and height | ||
| // code here | ||
| return length * width * height; | ||
| }; | ||
|
|
||
| // Do not modify code below this line. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
| const getBiggest = (x, y) => { | ||
| // x and y are integers. Return the larger integer | ||
| // if they are the same return either one | ||
| if (x > y) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually like to simplify You could also use a ternary operator: Which would simplify to |
||
| return x; | ||
| } | ||
| return y; | ||
| }; | ||
|
|
||
| const greeting = (language) => { | ||
|
|
@@ -11,15 +15,31 @@ const greeting = (language) => { | |
| // language: 'Spanish' -> 'Hola!' | ||
| // language: 'Chinese' -> 'Ni Hao!' | ||
| // if language is undefined return 'Hello!' | ||
| if (language === 'German') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, you could use a |
||
| return 'Guten Tag!'; | ||
| } else if (language === 'Spanish') { | ||
| return 'Hola!'; | ||
| } else if (language === 'Chinese') { | ||
| return 'Ni Hao!'; | ||
| } | ||
| return 'Hello!'; | ||
| }; | ||
|
|
||
| const isTenOrFive = (num) => { | ||
| // return true if num is 10 or 5 | ||
| // otherwise return false | ||
| if (num === 10 || num === 5) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const isInRange = (num) => { | ||
| // return true if num is less than 50 and greater than 20 | ||
| if (num < 50 && num > 20) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const isInteger = (num) => { | ||
|
|
@@ -29,13 +49,25 @@ const isInteger = (num) => { | |
| // -10 -> true | ||
| // otherwise return false | ||
| // hint: you can solve this using Math.floor | ||
| if (Math.floor(num) === num) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const fizzBuzz = (num) => { | ||
| // if num is divisible by 3 return 'fizz' | ||
| // if num is divisible by 5 return 'buzz' | ||
| // if num is divisible by 3 & 5 return 'fizzbuzz' | ||
| // otherwise return num | ||
| if (num % 3 === 0 && num % 5 === 0) { | ||
| return 'fizzbuzz'; | ||
| } else if (num % 5 === 0) { | ||
| return 'buzz'; | ||
| } else if (num % 3 === 0) { | ||
| return 'fizz'; | ||
| } | ||
| return num; | ||
| }; | ||
|
|
||
| const isPrime = (num) => { | ||
|
|
@@ -44,62 +76,107 @@ const isPrime = (num) => { | |
| // hint: a prime number is only evenly divisible by itself and 1 | ||
| // hint2: you can solve this using a for loop | ||
| // note: 0 and 1 are NOT considered prime numbers | ||
| if (num === 2) { | ||
| return true; | ||
| } else if (num === 0 || num === 1 || num % 2 === 0) { | ||
| return false; | ||
| } | ||
| for (let i = 3; i < num; i++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also have this skip all even numbers: |
||
| if (num % i === 0) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| }; | ||
|
|
||
| const returnFirst = (arr) => { | ||
| // return the first item from the array | ||
| return arr[0]; | ||
| }; | ||
|
|
||
| const returnLast = (arr) => { | ||
| // return the last item of the array | ||
| return arr[arr.length - 1]; | ||
| }; | ||
|
|
||
| const getArrayLength = (arr) => { | ||
| // return the length of the array | ||
| return arr.length; | ||
| }; | ||
|
|
||
| const incrementByOne = (arr) => { | ||
| // arr is an array of integers | ||
| // increase each integer by one | ||
| // return the array | ||
| for (let i = 0; i < arr.length; i++) { | ||
| arr[i] += 1; | ||
| } | ||
| return arr; | ||
| }; | ||
|
|
||
| const addItemToArray = (arr, item) => { | ||
| // add the item to the end of the array | ||
| // return the array | ||
| arr.push(item); | ||
| return arr; | ||
| }; | ||
|
|
||
| const addItemToFront = (arr, item) => { | ||
| // add the item to the front of the array | ||
| // return the array | ||
| // hint: use the array method .unshift | ||
| arr.unshift(item); | ||
| return arr; | ||
| }; | ||
|
|
||
| const wordsToSentence = (words) => { | ||
| // words is an array of strings | ||
| // return a string that is all of the words concatenated together | ||
| // spaces need to be between each word | ||
| // example: ['Hello', 'world!'] -> 'Hello world!' | ||
| let everyWord = words[0]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use reduce here. |
||
| for (let i = 1; i < words.length; i++) { | ||
| everyWord += ` ${words[i]}`; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need to wrap |
||
| } | ||
| return everyWord; | ||
| }; | ||
|
|
||
| const contains = (arr, item) => { | ||
| // check to see if item is inside of arr | ||
| // return true if it is, otherwise return false | ||
| return arr.includes(item); | ||
| }; | ||
|
|
||
| const addNumbers = (numbers) => { | ||
| // numbers is an array of integers. | ||
| // add all of the integers and return the value | ||
| let sum = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also a great time to use |
||
| for (let i = 0; i < numbers.length; i++) { | ||
| sum += numbers[i]; | ||
| } | ||
| return sum; | ||
| }; | ||
|
|
||
| const averageTestScore = (testScores) => { | ||
| // testScores is an array. Iterate over testScores and compute the average. | ||
| // return the average | ||
| let sum = 0; | ||
| for (let i = 0; i < testScores.length; i++) { | ||
| sum += testScores[i]; | ||
| } | ||
| return sum / testScores.length; | ||
| }; | ||
|
|
||
| const largestNumber = (numbers) => { | ||
| // numbers is an array of integers | ||
| // return the largest integer | ||
| let largest = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use |
||
| for (let i = 0; i < numbers.length; i++) { | ||
| if (numbers[i] > largest) { | ||
| largest = numbers[i]; | ||
| } | ||
| } | ||
| return largest; | ||
| }; | ||
|
|
||
| // Do not modify code below this line. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine but you can also simplify the whole function to look like this:
The value is automatically returned.