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.

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

function countNumbers() {

function countNumbers(arr) {
let i = 0
let objCounter = {}
while(i < arr.length) {
objCounter[arr[i]] = (objCounter[arr[i]] || 0) + 1
i++
}
return objCounter
}


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

function getCountriesSortedByPopulation() {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which array method can you use to return a new array with updated information inside? This array method will replace the two loops you have here.

return finalArr
}

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

function isOdd() {

function isOdd(n) {
if((n % 2) === 1){
return true
}
else{
return 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 i = n.toString()
return i.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can you condense this code to look cleaner? Consider chaining and implicit returns.

}

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

function removeEvenStrings() {

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

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) {
let newArr = []
let i = 0
while(i < arr.length){
if((i % 2) === 0){
newArr.push(arr[i])
}
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 = []
let i = 0
while(i < arr.length){
if((arr[i] % 2) === 0){
newArr.push(arr[i])
}
i++
}
return newArr
}

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

function removeVowels() {

function removeVowels(str) {
let i = 0
let vowelsRemoved = ''
while(i < str.length) {
if((str[i] !== 'a') && (str[i] !== 'e') && (str[i] !== 'i') && (str[i] !== 'o') && (str[i] !== 'u')) {
if((str[i] !== 'A') && (str[i] !== 'E') && (str[i] !== 'I') && (str[i] !== 'O') && (str[i] !== 'U')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explore using the .includes() method to make this function more readable.

vowelsRemoved = vowelsRemoved + str[i]
}
}
i++
}
return vowelsRemoved
}

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

function sevenBoom() {

function sevenBoom(n) {
let arr = []
let i = 1
while(i <= n){
if(((i % 7) === 0) || (i % 10) === 7){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider what would happen to the numbers 70-79. Would you receive the word "BOOM" with every number that contains 7?

arr[i-1] = "BOOM"
}
else{
arr[i-1] = i
}
i++
}
return arr
}

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 smallestNum = arr[0]
for(let i = 0; i < arr.length; i++) {
if(arr[i]< smallestNum) {
smallestNum = arr[i]
}
}
return smallestNum
}

module.exports = smallest