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.

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

function countNumbers() {

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


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

function getCountriesSortedByPopulation() {

function getCountriesSortedByPopulation(arr) {
let newArr = []
let sorted = arr.sort((a, b) => b.population - a.population)
sorted.forEach(e => newArr.push(e.country))

Choose a reason for hiding this comment

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

Since .map() returns an array, can you write this function so that you don't need newArr?

return newArr
}

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

function isOdd() {

function isOdd(n) {
if (n % 2 === 0) {

Choose a reason for hiding this comment

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

How can you use a ternary operator here?

return false
}
return true
}

module.exports = isOdd
9 changes: 7 additions & 2 deletions 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 count = 0
let num = n.toString()
for (let i of num) {
count += 1

Choose a reason for hiding this comment

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

What is a property that strings have which provides us with the number of characters in the string? You can use this property in place of the for loop.

}
return count
}

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

function removeEvenStrings() {

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

module.exports = removeEvenStrings
8 changes: 6 additions & 2 deletions problems/removeNumbersAtOddIndices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions problems/removeOddNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* ex: removeOddNumbers([2, 4, 6])
* returns: [2, 4, 6]
*/
function removeOddNumbers() {

function removeOddNumbers(arr) {
let filtered = arr.filter(e => e % 2 === 0)
return filtered
}

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

function removeVowels() {

function removeVowels(str) {
let vowel = 'aeiouAEIOU'
let newStr = ''
for (let i = 0; i < str.length; i += 1) {
if (!vowel.includes(str[i])) {
newStr += str[i]
}
}
return newStr
}

module.exports = removeVowels
13 changes: 11 additions & 2 deletions 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 newArr = []
for (let i = 1; i <= n; i += 1) {
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 numbers 70-79; will they be 'BOOM' based on this function? How can you find any number that contains a 7 in any digit?

newArr.push('BOOM')
}
else {
newArr.push(i)
}
}
return newArr
}

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

function smallest() {

function smallest(arr) {
let smallest = arr.reduce((acc, el) => {
if (acc < el) {
return acc
}
else {
return el
}
})
return smallest
}

module.exports = smallest