Skip to content

Instantly share code, notes, and snippets.

@izaakwalz
Created July 6, 2022 15:24
Show Gist options
  • Save izaakwalz/d3851a1659e7cb3ea895daeffd7ba43b to your computer and use it in GitHub Desktop.
Save izaakwalz/d3851a1659e7cb3ea895daeffd7ba43b to your computer and use it in GitHub Desktop.
algorithms challange
const assigment = {}
const myNumbers = [68, -68,27,94,72,-25,-51,32,10,64,-94,4,34,-86,90,81,20,-56,-91,-50]
function sumOfNumbers(arrayOfNumbers) {
return arrayOfNumbers.reduce((a,b) => a + b, 0)
// return arrayOfNumbers.length
} // chalange 1
function countEvenNumbers(arrayOfNumbers = []) {
let count = 0
for(let index = 0; index < arrayOfNumbers.length; index++) {
if (arrayOfNumbers[index] % 2 === 0) {
count++
}
}
return count
} // challange 2
console.log(assigment.countEvenNumbers = countEvenNumbers(myNumbers))
console.log(assigment.sumOfNumbers = sumOfNumbers(myNumbers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment