d51204436de9bfbf18e9203ce4e2a2e6 javascript1 lab4 v2 rasb14 2018-11-27 15:45:54 v3.1.3 (2018-09-13)
Generated 2018-11-27 16:45:54 by dbwebb lab-utility v3.1.3 (2018-09-13).
Practise arrays. You might find useful help here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
To copy an array use array.slice() to make a real copy, not a shallow one.
Create a variable array2 holding an array with the words: [candy,cake,cupcakes,lollipop,pringles]. Return the element on position: 2 in array2.
Answer with the result.
Use the variable array2. Concatenate the first item and the last item as a string. Separate the string with -.
Answer with the result.
Create an array, array1, with the items 49,72,-10,0,-412,739,6,1500.
Merge the two arrays, array1 and array2, into a third variable array3.
Answer with array3.
Create a variable array21 as a clone of array2.
Sort array21.
(Hint: http://stackoverflow.com/questions/3978492/javascript-fastest-way-to-duplicate-an-array-slice-vs-for-loop)
Answer with the resulting array.
Create a variable array11 as a copy of array1.
Sort array11 according to its values. The smallest value comes first and the largest value comes last.
Answer with the resulting array.
Create a variable array22 which holds the same content as array2 - but all strings are uppercase.
Use the built-in Array-function map() to solve it.
Answer with the array.
Create a new array, array12. It should contain all positive numbers from the array1.
Use the built-in array-function filter() to solve it.
Answer with the resulting array.
Create a function arrayAverage() that takes one array as argument and returns the average of all elements in that array.
Try out the function using array1 and answer with the rounded integer result.
Learn how to modify arrays.
Create a new array myArray and make it a copy of array1. Switch place on the first and the last element, with the help of built-in array-functions.
Use the array-functions pop(), push(), shift() and unshift().
Answer with myArray.
In myArray change the 3rd and 4th value to the boolean value false using built-in array-function splice().
Answer with the resulting array.
Remove the 4th and 5th item in ‘myArray’. Then insert the string MEGA after the item 3rd. Answer with the resulting array.
d51204436de9bfbf18e9203ce4e2a2e6