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.

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

function countNumbers() {

//count number returns an object, so create an empty object
//need to count the occurence of those numbers in the array
//needs to create a key of each number
//needs to add values that are the count of number

const countNumbers = (arr) => {
let count = {}
let i = 0
let counter = arr.forEach((key) => {
return count[key] = (count[key] || 0) + 1
})

return count

}


console.log(countNumbers([99, 99, 11, 12, 13, 58]))
module.exports = countNumbers
50 changes: 49 additions & 1 deletion problems/getCountriesSortedByPopulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,57 @@
* returns: ["China", "Egypt", "Denmark"]
*
*/
//takes in an array of objects
//and returns sorted by population value. (possibly using .sort)
let ex1 = [
{
country: "Algeria",
population: 41,
},
{
country: "Belize",
population: 0.4,
},
{
country: "China",
population: 1386,
},
{
country: "Denmark",
population: 6,
},
]

function getCountriesSortedByPopulation() {
let ex2 = [
{
country: "Argentina",
population: 58,
},
{
country: "Egypt",
population: 145,
},
{
country: "Russia",
population: 1386,
},
{
country: "New Zealand",
population: 66,
},
]

function getCountriesSortedByPopulation(arr) {
}
let sorted = []
for(let key in arr) {
sorted.push(key)
}
sorted.sort(function(a,b) {
return b-a
})


module.exports = getCountriesSortedByPopulation

console.log(getCountriesSortedByPopulation(ex1))
8 changes: 6 additions & 2 deletions problems/isOdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
* ex: isOdd(75); // true
*/

function isOdd() {

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

module.exports = isOdd

console.log(isOdd(4))
7 changes: 6 additions & 1 deletion problems/numberOfDigits.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

*/

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


}

module.exports = numberOfDigits

console.log(numberOfDigits(67))
11 changes: 9 additions & 2 deletions problems/removeEvenStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
* returns: []
*/

function removeEvenStrings() {

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

module.exports = removeEvenStrings

console.log(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) {

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

console.log(removeNumbersAtOddIndices([5, 4, 3, 2, 1]))
module.exports = removeNumbersAtOddIndices
11 changes: 7 additions & 4 deletions problems/removeOddNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* ex: removeOddNumbers([2, 4, 6])
* returns: [2, 4, 6]
*/
function removeOddNumbers() {
function removeOddNumbers(arr) {
let newArr = arr.filter((e) => {
return e % 2 === 0
})
return newArr
}

}

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

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

}

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

function sevenBoom() {
function sevenBoom(n) {
for(let i = 0; i < Array.length; i ++){

}return i
}

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

function smallest() {
function smallest(arr) {
let min = Math.min(...arr)
return(min)

}

module.exports = smallest
console.log(smallest([1, -1, 1, 1, 1]))