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.

27 changes: 17 additions & 10 deletions problems/countNumbers.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@

/**
/**
* Count all the numbers in an array
*
*
* @param {number[]} arr - An array containing numbers
* @returns {object} - an object where the key is the number, and the value is the count of that number
*
* ex: countNumbers([1,1,1,2,2,3,4])
*
* ex: countNumbers([1,1,1,2,2,3,4])
* returns { 1:3, 2:2, 3:1, 4:1 }
*
*
* ex: countNumbers([99, 99, 11, 12, 13, 58])
* returns { 99: 2, 11: 1, 12: 1, 13: 1, 58: 1 }
*/

function countNumbers() {

function countNumbers(arr) {
let count = {};
for (i = 0; i < arr.length; i++) {
let el = arr[i];
if (count[el]) {
count[el] += 1;
} else {
count[el] = 1;
}
}
return count;
}


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

function getCountriesSortedByPopulation() {
function getCountriesSortedByPopulation(arr) {
return arr.sort((country1, country2) => country1.population < country2.population ? 1 :-1).map(el => el.country)

}

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

function isOdd() {

function isOdd(n) {
if (n % 2 === 1 || n % 2 === -1) {
return true
} else
return false
}

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

*/

function numberOfDigits() {

function numberOfDigits(n) {
let digitSum = 0;
if (n >= 1)
digitSum ++
while (n / 10 >= 1) {
n /= 10;
digitSum ++
}
return digitSum
}

module.exports = numberOfDigits
module.exports = numberOfDigits;
10 changes: 7 additions & 3 deletions problems/removeEvenStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
* returns: []
*/

function removeEvenStrings() {

function removeEvenStrings(arr) {
newArr = [];
for (let i = 0; i <= arr.length; i += 2) {
arr.splice(i % 2)
}
return newArr
}

module.exports = removeEvenStrings
module.exports = removeEvenStrings;
35 changes: 20 additions & 15 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() {

/** 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(arr) {
let numsCopy = [];
for (let i = 0; i <= arr.length - 1; i++)
if (arr[i] % 2 === 0) {
numsCopy.push(arr[i]);
}
return numsCopy;
}

module.exports = removeNumbersAtOddIndices
module.exports = removeNumbersAtOddIndices;
9 changes: 7 additions & 2 deletions problems/removeOddNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
* ex: removeOddNumbers([2, 4, 6])
* returns: [2, 4, 6]
*/
function removeOddNumbers() {

function removeOddNumbers(arr) {
let numsCopy = [];
for (let i = 0; i <= arr.length - 1; i++)
if (arr[i] % 2 === 0) {
numsCopy.push(arr[i]);
}
return numsCopy;
}

module.exports = removeOddNumbers
43 changes: 25 additions & 18 deletions problems/removeVowels.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
/**
* 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 noVowels = "";
let vowels = "aeiouAEIOU";
for (let i = 0; i < str.length; i++) {
let letters = str[i];
if (!vowels.includes(letters)) {
noVowels += letters;
}
}
return noVowels;
}

module.exports = removeVowels
module.exports = removeVowels;
12 changes: 10 additions & 2 deletions problems/sevenBoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
* 17 is also replaced with 'BOOM' because it contains a 7.
*/

function sevenBoom() {

function sevenBoom(n) {
let arr = []
for (let i = 1; i < n; i++)
if (i % 7 === 0)
arr.push("BOOM")
else if (i === 1)
arr.push ("BOOM")
else
arr.push(i)
return arr
}

module.exports = sevenBoom
9 changes: 7 additions & 2 deletions problems/smallest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
* returns 1 (does not matter if it is the first or second 1)
*/

function smallest() {

function smallest(arr) {
let smallest = arr[0];
for (let i = 0; i <= arr.length - 1; i++)
if (arr[i] < smallest) {
smallest = arr[i];
}
return smallest;
}

module.exports = smallest