Created
February 21, 2022 19:34
-
-
Save appoll/38aaf5e43f28022f3711ee3470ccd1bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ages = [12, 16, 24, 28, 69, 14, 13, 80] | |
// E0. Copy all ages which are greater than 18 to a second array | |
largerThan18 = [] | |
for (i=0; i < ages.length; i++){ | |
} | |
console.log("Input: " + ages); | |
console.log("Result: " + largerThan18); | |
// E1. Create an array which contains the positions of all ages above 18 | |
largerThan18Positions = [] | |
for (i=0; i < ages.length; i++){ | |
} | |
console.log("Input: " + ages); | |
console.log("Result: " + largerThan18Positions); | |
// E2 | |
// Starting from the ages array, create two other arrays: | |
// underAge - containing the ages < 18 and legalAge - containing the ages >= 18 | |
ages = [12, 16, 24, 28, 69, 14, 13, 80] | |
legalAge = [] | |
underAge = [] | |
for (i=0; i < ages.length; i++){ | |
} | |
console.log("Input: " + ages); | |
console.log("Result underAge: " + underAge); | |
console.log("Result legalAge: " + legalAge); | |
// E3. | |
// Start with 2 hardcoded arrays, e.g. prices1 & prices2 | |
// Calculate a third array that contains the sum of the elements in the first two arrays. | |
prices1 = [12, 16, 24, 28] | |
prices2 = [1, 1, 1, 1] | |
pricesSum = [] | |
for (i=0; i < prices1.length; i++){ | |
} | |
console.log("Result: " + pricesSum); | |
// expected result: [13, 17, 25, 29] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment