Skip to content

Commit

Permalink
solved_Huni
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipolyi-Gáts Hunor committed Dec 17, 2024
1 parent fdcead4 commit d748f7f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
20 changes: 19 additions & 1 deletion solutions/averageAgeOfAdults.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,26 @@ You do not have to deal with the case, when there are only underage users in the
*/

function averageAgeOfAdults(users) {
// let users = {
// "id": 123,
// "name": "Alex Smith",
// "age": 20,
// }

function averageAgeOfAdults(users) {
let numberOfAdults = 0;
let sumOfAdultAges = 0;
for (let person of users){
if (parseInt(person.age) >= 18){
numberOfAdults += 1;
sumOfAdultAges += parseInt(person.age);
}
}
let result = sumOfAdultAges / numberOfAdults;
// console.log(result);
return result
}

// console.log(averageAgeOfAdults(users));

module.exports = averageAgeOfAdults;
12 changes: 12 additions & 0 deletions solutions/countConfirmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ If you receive an array which contains only one user object where the isConfirme
*/

function countConfirmed(users) {

if (users.length === 1 && users[0]["isConfirmed"] === true){
return 1;
}

let count = 0;
for (let user of users){
if (user.isConfirmed === true){
count += 1;
}
}

return count;
}

module.exports = countConfirmed;
16 changes: 16 additions & 0 deletions solutions/filterDivisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ Be mindful of division by 0. If the given number is 0 then return null.
If the array is empty then it should return an empty array.
*/

// let numbers = [1,2,3,4,5,6,7,8,9,10];
// let divisor = 3;

function filterDivisible(numbers, divisor) {
let arrayOfDivisibles = [];
if (numbers.length < 1){
return arrayOfDivisibles;
} else if (divisor === 0){
return null;
}

for (let number of numbers){
if ((number % divisor) === 0){
arrayOfDivisibles.push(number);
}
}
return arrayOfDivisibles;

}

Expand Down
7 changes: 6 additions & 1 deletion solutions/findAbacus.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ The wrong object may contain the key abacus but with false value! There may only
*/

function findAbacus(array) {

for (let index = 0; index < array.length; index++){
if (`abacus` in array[index] === true && array[index]["abacus"] === true){
return index;
}
}
return null;
}

module.exports = findAbacus;

0 comments on commit d748f7f

Please sign in to comment.