Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,714 changes: 5,712 additions & 2 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions problems/countNumbers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Count all the numbers in an array
*
Expand All @@ -12,8 +11,19 @@
* returns { 99: 2, 11: 1, 12: 1, 13: 1, 58: 1 }
*/

function countNumbers() {

function countNumbers(arr) {
let countNum = {}

arr.forEach((arr) => {
if (countNum[arr]) {
countNum[arr] = countNum[arr] + 1
} else {
countNum[arr] = 1
}
})

return countNum

}


Expand Down
7 changes: 5 additions & 2 deletions problems/getCountriesSortedByPopulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
*
*/

function getCountriesSortedByPopulation() {
function getCountriesSortedByPopulation(arr) {

return arr

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?


}

module.exports = getCountriesSortedByPopulation

module.exports = getCountriesSortedByPopulation
5 changes: 3 additions & 2 deletions problems/isOdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
* ex: isOdd(75); // true
*/

function isOdd() {
function isOdd(n) {
return ((n % 2) == 1)

}

module.exports = isOdd
module.exports = isOdd
7 changes: 5 additions & 2 deletions problems/numberOfDigits.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

*/

function numberOfDigits() {
function numberOfDigits(n) {
if (n === 0)
return 0
return n.toString().length

}

module.exports = numberOfDigits
module.exports = numberOfDigits
17 changes: 15 additions & 2 deletions problems/removeEvenStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@
* returns: []
*/

function removeEvenStrings() {
function removeEvenStrings(arr) {

// let newArray = arr.filter((arr) => {
// return arr % 2 === 0
// })
// return newArray
// };

let even = ['']

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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
29 changes: 17 additions & 12 deletions problems/removeNumbersAtOddIndices.js
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
38 changes: 21 additions & 17 deletions problems/removeOddNumbers.js
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
44 changes: 27 additions & 17 deletions problems/removeVowels.js
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
26 changes: 12 additions & 14 deletions problems/sevenBoom.js
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
36 changes: 19 additions & 17 deletions problems/smallest.js
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