Skip to content
Open

done #63

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.

16 changes: 14 additions & 2 deletions problems/countNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
* 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++) {

let num = arr[i];
obj[num] = obj[num] ? obj[num] + 1 : 1
}
return obj;
}








module.exports = countNumbers
5 changes: 4 additions & 1 deletion problems/getCountriesSortedByPopulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
*
*/

function getCountriesSortedByPopulation() {
function getCountriesSortedByPopulation(arr) {
return arr.sort((a1, a2) => a1.population < a2.population ? 1 :-1).map(el => el.country)



}

Expand Down
8 changes: 7 additions & 1 deletion problems/isOdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
* ex: isOdd(75); // true
*/

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

}else{
return false
}

}

Expand Down
5 changes: 4 additions & 1 deletion problems/numberOfDigits.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

*/

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


}

Expand Down
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 newOdd = []
for(let i = 0; i < arr.length; i++){
if(arr[i].length%2 !==0 ){
newOdd.push(arr[i])
}
}
return newOdd
}



module.exports = removeEvenStrings
7 changes: 6 additions & 1 deletion problems/removeNumbersAtOddIndices.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* ex: removeNumbersAtOddIndices([5, 4, 3, 2, 1]);
* returns: [5, 3, 1]
*/
function removeNumbersAtOddIndices() {
function removeNumbersAtOddIndices(arr) {
let index = []
for(let i= 0; i < arr.length;i+= 2){
index.push(arr[i])
}
return index

}

Expand Down
9 changes: 8 additions & 1 deletion problems/removeOddNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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

}

Expand Down
10 changes: 8 additions & 2 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 = ""
for (let i = 0; i < str.length; i++) {
if (str[i] !== 'a' && str[i] !== 'e' && str[i] !== 'i' && str[i] !== 'o' && str[i] !== 'u' && str[i] !== 'A' && str[i] !== 'E' && str[i] !== 'I' && str[i] !== 'O' && str[i] !== 'U') {
vowel += str[i]
}
}
return vowel
}

module.exports = removeVowels
11 changes: 10 additions & 1 deletion problems/sevenBoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
* 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 || i.toString().includes(7)||i % 7 ===0 ){
newarr.push("BOOM")
}else{
newarr.push(i)
}
}
return newarr

}

Expand Down
17 changes: 15 additions & 2 deletions problems/smallest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@
* returns 1 (does not matter if it is the first or second 1)
*/

function smallest() {

// i = 0
// arr[i] = 3 // small = 3
// i = 1
// arr[i] = 0 // small = 0

function smallest(arr) {
let smallNumber = arr[0]
for(let i = 0; i < arr.length; i++){
if(arr[i] < smallNumber){
smallNumber = arr[i]
}

}
return smallNumber
}

module.exports = smallest