Skip to content
Open
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
30 changes: 21 additions & 9 deletions session3/index_extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
// Return a sum of all parameters entered regardless of the amount of numbers - NO ARRAYS
// ex. addAll(2,5,6,7) === 20

function addAll() {}
function addAll() { }

// CHALLENGE 2: SUM ALL PRIMES
// Pass in a number to loop up to and add all of the prime numbers. A prime number is a whole number greater than 1 whose only factors are 1 and itself
// ex. sumAllPrimes(10) == 17

function sumAllPrimes() {}
function sumAllPrimes() { }

// CHALLENGE 3: SEEK & DESTROY
// Remove from the array whatever is in the following arguments. Return the leftover numbers in an array
// ex. seekAndDestroy([2, 3, 4, 6, 6, 'hello'], 2, 6) == [3, 4, 'hello']

function seekAndDestroy() {}
function seekAndDestroy() { }

// CHALLENGE 4: SORT BY HEIGHT
// Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees.
Expand All @@ -28,11 +28,11 @@ function seekAndDestroy() {}
// sortByHeight(a) == [-1, 150, 160, 170, -1, -1, 180, 190]

function sortByHeight() {
// SOLUTION BY Smollet777
// filtering out and sorting all "humans"
// const humans = a.filter(v => v !== -1).sort((a, b) => a - b)
// put sorted "humans" back
// return a.map(v => v !== -1? humans.shift() : -1)
// SOLUTION BY Smollet777
// filtering out and sorting all "humans"
// const humans = a.filter(v => v !== -1).sort((a, b) => a - b)
// put sorted "humans" back
// return a.map(v => v !== -1? humans.shift() : -1)
}

// CHALLENGE 5: MISSING LETTERS
Expand Down Expand Up @@ -79,4 +79,16 @@ console.log('Missing: ' + missingLetters(letters)) // `Missing: l, q`;
// ex.
// evenOddSums([50, 60, 60, 45, 71]) == [170, 116]

function evenOddSums() {}
function evenOddSums(arr) {
// SOLUTION BY Aizhan87
let evenNums = 0;
let oddNums = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
evenNums += arr[i]
} else {
oddNums += arr[i]
}
}
return [evenNums, oddNums]
}