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,9 +12,17 @@
* 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++) {
let num = arr[i]
count[num] = count[num] ? count[num] + 1 : 1
}
return count
}

let arr = [99, 99, 11, 12, 13, 58]
console.log(countNumbers(arr))


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

function getCountriesSortedByPopulation() {

function getCountriesSortedByPopulation(arr) {
return arr.sort((a, b) =>
b.population - a.population).map(str => str.country)
}

module.exports = getCountriesSortedByPopulation
// let arr = [51, 10, 12];

arr = [
{
country: "Algeria",
population: 41,
},
{
country: "Belize",
population: 0.4,
},
{
country: "China",
population: 1386,
},
{
country: "Denmark",
population: 6,
},
]

console.log(getCountriesSortedByPopulation(arr))

// console.log(arr)


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

function isOdd() {

function isOdd(n) {
if(n % 2 !== 0){
return true
} else {
return false
}
}

console.log(isOdd(4))

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) {
return n.toString().length
}

let n = 123456789
console.log(numberOfDigits(n))

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

function removeEvenStrings() {

function removeEvenStrings(arr) {
return arr.filter(str => str.length % 2 === 1)
}

let arr = ([
"The",
"only",
"thing",
"we",
"have",
"to",
"fear",
"is",
"fear",
"itself",
])


// console.log(arr[0].length)

console.log(removeEvenStrings(arr))

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

function removeNumbersAtOddIndices(arr) {
for (let i = 0; i < arr.length; i++){
arr.splice(i + 1, 1)
}
return arr;
}


arr = [0, 1, 2, 3, 4]

console.log(removeNumbersAtOddIndices(arr))

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 evens = arr.filter ((num) => {
if(num % 2 === 0){
return true
}
})
return evens
}

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

function removeVowels() {

function removeVowels(str) {
str = str.replace( /[aeiou]/ig, '' )
return str
}

module.exports = removeVowels
10 changes: 7 additions & 3 deletions problems/sevenBoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
* 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++){
i % 7 === 0 || i % 10 === 7 ? arr.push("BOOM") : arr.push(i)
}
return arr
}

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

function smallest() {

function smallest(arr) {
arr.sort(function(a, b){return a-b})
return arr[0]
}

module.exports = smallest