-
Notifications
You must be signed in to change notification settings - Fork 39
TA exam #67
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
base: master
Are you sure you want to change the base?
TA exam #67
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,21 @@ | |
| * returns: [] | ||
| */ | ||
|
|
||
| function removeEvenStrings() { | ||
| function removeEvenStrings(arr) { | ||
|
|
||
| // let newArray = arr.filter((arr) => { | ||
| // return arr % 2 === 0 | ||
| // }) | ||
| // return newArray | ||
| // }; | ||
|
|
||
| let even = [''] | ||
|
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. Do you want even to be an array with an empty string in it or just an empty array? |
||
| for (let i = 0; i < arr.length; i++) { | ||
| if (arr[i] % 2 === 0) { | ||
|
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. Reconsider what this conditional is checking. What does arr[i] evaluate to? |
||
| even.push(arr[i]) | ||
| } | ||
| } | ||
| return arr | ||
| } | ||
|
|
||
| module.exports = removeEvenStrings | ||
| module.exports = removeEvenStrings | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,22 @@ | ||
| /** Takes an array of numbers and returns a new array | ||
| * with only the numbers at odd indices in the input array. | ||
| * | ||
| * @param {number[]} arr - The input array | ||
| * @returns {number[]} - An array removing all elements initially appearing at an odd index | ||
| * | ||
| * ex: removeNumbersAtOddIndices([0, 1, 2, 3, 4]); | ||
| * returns: [0, 2, 4] | ||
| * | ||
| * ex: removeNumbersAtOddIndices([5, 4, 3, 2, 1]); | ||
| * returns: [5, 3, 1] | ||
| */ | ||
| function removeNumbersAtOddIndices() { | ||
| * with only the numbers at odd indices in the input array. | ||
| * | ||
| * @param {number[]} arr - The input array | ||
| * @returns {number[]} - An array removing all elements initially appearing at an odd index | ||
| * | ||
| * ex: removeNumbersAtOddIndices([0, 1, 2, 3, 4]); | ||
| * returns: [0, 2, 4] | ||
| * | ||
| * ex: removeNumbersAtOddIndices([5, 4, 3, 2, 1]); | ||
| * returns: [5, 3, 1] | ||
| */ | ||
| function removeNumbersAtOddIndices(arr) { | ||
|
|
||
| for (let i = 0; i < arr.length; i++) { | ||
| arr.splice(i + 1, 1) | ||
| } | ||
|
|
||
| return arr | ||
| } | ||
|
|
||
| module.exports = removeNumbersAtOddIndices |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,25 @@ | ||
| /** Takes an array of numbers and returns a new array. | ||
| * The returned array contains only the even numbers from the input array, | ||
| * with no odd numbers. | ||
| * | ||
| * @param {number[]} arr - The input array | ||
| * @returns {number[]} - The input array with all odd number removed | ||
| * | ||
| * ex: removeOddNumbers([3, 5, 7, 2, 4, 9, 11, 6]); | ||
| * returns: [2, 4, 6] | ||
| * | ||
| * ex: removeOddNumbers([1, 3, 5]) | ||
| * returns: [] | ||
| * | ||
| * ex: removeOddNumbers([2, 4, 6]) | ||
| * returns: [2, 4, 6] | ||
| */ | ||
| function removeOddNumbers() { | ||
| * The returned array contains only the even numbers from the input array, | ||
| * with no odd numbers. | ||
| * | ||
| * @param {number[]} arr - The input array | ||
| * @returns {number[]} - The input array with all odd number removed | ||
| * | ||
| * ex: removeOddNumbers([3, 5, 7, 2, 4, 9, 11, 6]); | ||
| * returns: [2, 4, 6] | ||
| * | ||
| * ex: removeOddNumbers([1, 3, 5]) | ||
| * returns: [] | ||
| * | ||
| * ex: removeOddNumbers([2, 4, 6]) | ||
| * returns: [2, 4, 6] | ||
| */ | ||
| function removeOddNumbers(arr) { | ||
| let newArr = arr.filter((num) => { | ||
| return num % 2 === 0 | ||
| }) | ||
| return newArr | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| module.exports = removeOddNumbers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,31 @@ | ||
| /** | ||
| * Removes all vowels from an input string. | ||
| * For this problem, treat y as a consonant, not a vowel. | ||
| * Vowels are "a", "e", "i", "o", and "u" (upper and lowercase) | ||
| * | ||
| * @param {string} str - The input string | ||
| * @returns {string} - Returns a new string without any vowels. | ||
| * | ||
| * ex: removeVowels("HELLO") | ||
| * returns: "HLL" | ||
| * | ||
| * ex: removeVowels("Sunny") | ||
| * returns: "Snny" | ||
| * | ||
| */ | ||
|
|
||
| function removeVowels() { | ||
| * Removes all vowels from an input string. | ||
| * For this problem, treat y as a consonant, not a vowel. | ||
| * Vowels are "a", "e", "i", "o", and "u" (upper and lowercase) | ||
| * | ||
| * @param {string} str - The input string | ||
| * @returns {string} - Returns a new string without any vowels. | ||
| * | ||
| * ex: removeVowels("HELLO") | ||
| * returns: "HLL" | ||
| * | ||
| * ex: removeVowels("Sunny") | ||
| * returns: "Snny" | ||
| * | ||
| */ | ||
|
|
||
| function removeVowels(str) { | ||
| let i = 0 | ||
| let empty = '' | ||
| while (i < str.length) { | ||
| if ((str[i] !== 'a') && (str[i] !== 'e') && (str[i] !== 'i') && (str[i] !== 'o') && (str[i] !== 'u')) { | ||
| if ((str[i] !== 'A') && (str[i] !== 'E') && (str[i] !== 'I') && (str[i] !== 'O') && (str[i] !== 'U')) { | ||
| empty = empty + str[i] | ||
| } | ||
| } | ||
| i++ | ||
| } | ||
| return empty | ||
| } | ||
|
|
||
| module.exports = removeVowels | ||
| module.exports = removeVowels |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,16 @@ | ||
| /** Write a function that returns all the values from 1 to n inclusive, replacing all numbers that are a multiple of seven, or contain seven with "BOOM". | ||
| * | ||
| * @param {number} n - The number to count up to | ||
| * @returns {number[]} - An array matching the pattern described above | ||
| * | ||
| * ex: sevenBoom(20) | ||
| * returns: [1,2,3,4,5,6,'BOOM',8,9,10,11,12,13,'BOOM',15,16,'BOOM',18,19,20] | ||
| * Notice: | ||
| * 7 is replaced with 'BOOM' because it is a multiple of 7 (7 * 1 = 7) AND it contains a 7. | ||
| * 14 is replaced with 'BOOM' because it is a multiple of 7 (7 * 2 = 14) | ||
| * 17 is also replaced with 'BOOM' because it contains a 7. | ||
| */ | ||
| * | ||
| * @param {number} n - The number to count up to | ||
| * @returns {number[]} - An array matching the pattern described above | ||
| * | ||
| * ex: sevenBoom(20) | ||
| * returns: [1,2,3,4,5,6,'BOOM',8,9,10,11,12,13,'BOOM',15,16,'BOOM',18,19,20] | ||
| * Notice: | ||
| * 7 is replaced with 'BOOM' because it is a multiple of 7 (7 * 1 = 7) AND it contains a 7. | ||
| * 14 is replaced with 'BOOM' because it is a multiple of 7 (7 * 2 = 14) | ||
| * 17 is also replaced with 'BOOM' because it contains a 7. | ||
| */ | ||
|
|
||
| function sevenBoom() { | ||
|
|
||
| } | ||
| function sevenBoom() {} | ||
|
|
||
| module.exports = sevenBoom |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| /** | ||
| * Return the smallest number in an array of numbers. | ||
| * | ||
| * @param {number[]} arr - The input array of numbers | ||
| * @returns {number} - Returns smallest number | ||
| * | ||
| * ex: smallest([3, 0]) | ||
| * returns 0 | ||
| * | ||
| * ex: smallest([1, -1, 1, 1, 1]) | ||
| * returns -1 | ||
| * | ||
| * ex: smallest([1, 1, 2]) | ||
| * returns 1 (does not matter if it is the first or second 1) | ||
| */ | ||
| * Return the smallest number in an array of numbers. | ||
| * | ||
| * @param {number[]} arr - The input array of numbers | ||
| * @returns {number} - Returns smallest number | ||
| * | ||
| * ex: smallest([3, 0]) | ||
| * returns 0 | ||
| * | ||
| * ex: smallest([1, -1, 1, 1, 1]) | ||
| * returns -1 | ||
| * | ||
| * ex: smallest([1, 1, 2]) | ||
| * returns 1 (does not matter if it is the first or second 1) | ||
| */ | ||
|
|
||
| function smallest(arr) { | ||
|
|
||
| return Math.min.apply(Math, arr) | ||
|
|
||
| function smallest() { | ||
|
|
||
| } | ||
|
|
||
| module.exports = smallest | ||
| module.exports = smallest |
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.
Which array method can we use to organize by ascending or descending order?