diff --git a/solutions/averageAgeOfAdults.js b/solutions/averageAgeOfAdults.js index c52b813..61ff15b 100644 --- a/solutions/averageAgeOfAdults.js +++ b/solutions/averageAgeOfAdults.js @@ -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; diff --git a/solutions/countConfirmed.js b/solutions/countConfirmed.js index 240f926..9828166 100644 --- a/solutions/countConfirmed.js +++ b/solutions/countConfirmed.js @@ -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; diff --git a/solutions/filterDivisible.js b/solutions/filterDivisible.js index 308c21f..a1f851d 100644 --- a/solutions/filterDivisible.js +++ b/solutions/filterDivisible.js @@ -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; } diff --git a/solutions/findAbacus.js b/solutions/findAbacus.js index d337e41..78981bd 100644 --- a/solutions/findAbacus.js +++ b/solutions/findAbacus.js @@ -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;