Skip to content

Instantly share code, notes, and snippets.

@appoll
Created May 28, 2021 18:39
Show Gist options
  • Save appoll/0c361ec9a0bdfac131d1a5a583f8f75e to your computer and use it in GitHub Desktop.
Save appoll/0c361ec9a0bdfac131d1a5a583f8f75e to your computer and use it in GitHub Desktop.
ages = [12, 16, 24, 28, 69, 14, 13, 80]
// I can copy values from one array into another
// Copy all ages which are greater than 18 to a second array
largerThan18 = []
for (i=0; i < ages.length; i++){
if (ages[i] > 18){
largerThan18.push(ages[i]);
}
}
console.log("Input: " + ages);
console.log("Result: " + largerThan18);
// Start with 2 hardcoded arrays.
// 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]
// expected result: [13, 17, 25, 29]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment