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.

12 changes: 10 additions & 2 deletions problems/countNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
* returns { 99: 2, 11: 1, 12: 1, 13: 1, 58: 1 }
*/

function countNumbers() {

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


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

function getCountriesSortedByPopulation() {

function getCountriesSortedByPopulation(arr) {
let newArr = []
arr.sort((a,b) => b.population - a.population)
for(let i =0; i<arr.length; i++) {
newArr.push(arr[i].country)
}
return newArr
}

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

function isOdd() {

function isOdd(n) {
return n % 2 ===1 ? true : false
}

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

*/

function numberOfDigits() {

function numberOfDigits(n) {
let str = n.toString()
return str.length
}

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

function removeEvenStrings() {

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

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

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


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

function removeOddNumbers(arr) {
let newArr = []
for(let i =0; i < arr.length; i++) {
if(arr[i] % 2 === 0) {
newArr.push(arr[i])
} else {

}
}
return newArr
}

module.exports = removeOddNumbers
22 changes: 21 additions & 1 deletion problems/removeVowels.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,28 @@
*
*/

function removeVowels() {
function removeVowels(str) {
let newStr = ''
for(let i = 0; i < str.length; i++) {
if(str[i].toLowerCase() !== "a" && str[i].toLowerCase() !== "e" && str[i].toLowerCase() !== "i" && str[i].toLowerCase() !== "o" && str[i].toLowerCase() !== "u") {
newStr += str[i]
}

}
return newStr
}

// let vowels = ["a", "e", "i", "o", "u"]
// let newStr = "";
// for(let i = 0; i < str.length; i++) {
// let letter =str[i].toUpperCase
// if(!vowels.includes(letter)) {
// newStr += str[i];
// } else {
// newStr += str[i]
// }
// };
// return newStr;


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

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

}
return num
}

module.exports = sevenBoom
10 changes: 8 additions & 2 deletions problems/smallest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
* 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; i++) {
if(arr[i] < smallest) {
smallest = arr[i]
}
}
return smallest
}

module.exports = smallest