diff --git a/problems/countNumbers.js b/problems/countNumbers.js index 3a86643..f1a2fc2 100644 --- a/problems/countNumbers.js +++ b/problems/countNumbers.js @@ -12,8 +12,17 @@ * returns { 99: 2, 11: 1, 12: 1, 13: 1, 58: 1 } */ -function countNumbers() { - +function countNumbers(arr) { + let mapped = {} + for (let i = 0; i < arr.length; i++) { + if (mapped[arr[i]] === undefined) { + mapped[arr[i]] = 1 + } + else { + mapped[arr[i]] += 1 + } + } + return mapped } diff --git a/problems/getCountriesSortedByPopulation.js b/problems/getCountriesSortedByPopulation.js index 6e73ba8..e34ce47 100644 --- a/problems/getCountriesSortedByPopulation.js +++ b/problems/getCountriesSortedByPopulation.js @@ -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 diff --git a/problems/isOdd.js b/problems/isOdd.js index e93efee..a2ff141 100644 --- a/problems/isOdd.js +++ b/problems/isOdd.js @@ -9,8 +9,13 @@ * ex: isOdd(75); // true */ -function isOdd() { - +function isOdd(n) { +if(n % 2 ===0){ + return false +} +else{ + return true +} } module.exports = isOdd diff --git a/problems/numberOfDigits.js b/problems/numberOfDigits.js index a90ca53..a1d6641 100644 --- a/problems/numberOfDigits.js +++ b/problems/numberOfDigits.js @@ -7,8 +7,8 @@ */ -function numberOfDigits() { - +function numberOfDigits(n) { + return n.toString().length } module.exports = numberOfDigits diff --git a/problems/removeEvenStrings.js b/problems/removeEvenStrings.js index b5e8052..b517405 100644 --- a/problems/removeEvenStrings.js +++ b/problems/removeEvenStrings.js @@ -19,8 +19,17 @@ * returns: [] */ -function removeEvenStrings() { +function removeEvenStrings(arr) { +let newArr = [] +for(let i = 0; i < arr.length; i++){ + if(arr[i].length % 2 === 0){ + } + else{ + newArr.push(arr[i]) + } +} +return newArr } module.exports = removeEvenStrings diff --git a/problems/removeNumbersAtOddIndices.js b/problems/removeNumbersAtOddIndices.js index 94d03a0..d269704 100644 --- a/problems/removeNumbersAtOddIndices.js +++ b/problems/removeNumbersAtOddIndices.js @@ -10,8 +10,12 @@ * 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 \ No newline at end of file diff --git a/problems/removeOddNumbers.js b/problems/removeOddNumbers.js index cbfe4eb..853c3e6 100644 --- a/problems/removeOddNumbers.js +++ b/problems/removeOddNumbers.js @@ -14,8 +14,14 @@ * 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]) + } +} +return newArr } module.exports = removeOddNumbers \ No newline at end of file diff --git a/problems/removeVowels.js b/problems/removeVowels.js index be7edc6..610a3e9 100644 --- a/problems/removeVowels.js +++ b/problems/removeVowels.js @@ -14,8 +14,18 @@ * */ -function removeVowels() { - +function removeVowels(str) { + let newString = '' + for (let i = 0; i < str.length; i++) { + if (str[i].toLocaleLowerCase() !== 'a' && str[i].toLocaleLowerCase() !== 'e' && str[i].toLocaleLowerCase() !== 'i' && str[i].toLocaleLowerCase() !== 'o' && str[i].toLocaleLowerCase() !== 'u' ){ + newString +=str[i] + } + + + + +} +return newString } module.exports = removeVowels diff --git a/problems/sevenBoom.js b/problems/sevenBoom.js index a77a8f9..fe64683 100644 --- a/problems/sevenBoom.js +++ b/problems/sevenBoom.js @@ -11,8 +11,18 @@ * 17 is also replaced with 'BOOM' because it contains a 7. */ -function sevenBoom() { - +function sevenBoom(n) { + let newArr = [] + for(let i = 1; i <= n;i++){ + if(i % 7 === 0 || i% 10 === 7){ + newArr.push('BOOM') + } + else{ + newArr.push(i) + } + + } + return newArr } module.exports = sevenBoom \ No newline at end of file diff --git a/problems/smallest.js b/problems/smallest.js index 931bf25..6af6566 100644 --- a/problems/smallest.js +++ b/problems/smallest.js @@ -14,8 +14,15 @@ * 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 } +console.log(smallest([5, 1, 4, 2, 5, 6])) module.exports = smallest