CSC 15 Lab 5: Functions, Loops, and Arrays This class will ask you to write series of functions using loops and arrays and strings. 0. Write a function largesti that returns the INDEX of the largest element in an array (which is passed in as a parameter). If there are multiple occurrences of the largest element, the function should return -1. For example, largesti([2,4,1,7,3]) should return 3, since the largest element, 7, is at position 3. largest([4,1,6,2,6]) should return -1 because there's a tie. This should be straight from your notes so it should be called a warmup. Devise several function calls to make sure the code is working correctly. e.g. largesti([2,4,1,7,3]) 1. Write a function 'minnn' that takes an array as a parameter and returns the smallest NON-NEGATIVE NUMBER in the array. For example, calling minnn([4,2,-4,1,-5,7]) should return 1, which is the smallest non-negative number. If all the elements in the array are negative, your function should return 0. 2. Write a function 'oddcount' that counts the number of odd numbers in an array. For example, oddcount([2,5,4,8,9,10]) should return 2 because there are two odd numbers (5 and 9) in the array. A number is odd if the remainder after division by 2 is 1. 3. Write a function that takes an array as a parameter and returns a new array, with every element in the original array doubled. Call the function twox. For example, twox([1,4,6,8]) should return [2,8,12,16]. It constructs a NEW array with every element in the parameter array doubled. Hint: start with an empty array B =[] and use append. Devise sample calls ... 4. Write a function that takes an array as a parameter and return an array that contains EVERY OTHER ELEMENT of the input paramter. for example, calling your function everyother([1,3,2,6,4,8]) should return the array [1,2,4]. The first element of the array should always be included. If the input parameter is the empty array [], the function should also return []. 5. Write a function that takes two array as parameters and interleaves them. For this problem if the two arrays are not of the same length, you can "raise an exception": raise "input error" For example, interleave([1,3,5,7], [4,6,8,9]) should return the array [1,4,3,6,5,8,7,9]. 6. (slightly more challenging) Write a function that returns the INTERSECTION of two arrays. The intersection is the array that contains all elements that belong to both input arrays: For example, intersection([3,1,5,2], [8,4,1,6,3]) should return [3,1] (or [1,3], which is fine too), which is contains all elements that belong to both arrays. Duplicates are fine (the intersection may contain duplicate elements as long as the elements are also duplicated in both input arrays). Hint: to find the intersectionof A and B, go through each element of A and check if its also in B. Use the built-in 'in' operator. to test if an element is contained in an array. ---------------------- Optional but Recommended: -------------------------- 7a. Mild Challenge: Write a function that takes an array parameter and return the same array without duplicates. For example, calling nodups([3,4,1,3,5,1] should return [3,4,1,5]. All duplicates are removed. Hint: don't try to delete an element from an array. Instead, construct a new array, starting from [], that does not include duplicates. 7b. MEGA Challenge: Modify problem 0 so that instead of returning -1 when there is a tie for the largest value, the function returns an array containing the indices of all occurrences of the largest element. For example, largests([3,5,8,2,8,4]) should return [2,4] because the largest element (8) is found at positions 2 and 4 in the array. 7c. GIGA Challenge: The "median" value of an array is an element such that there are an equal number of elements less than the median as there are greater than the median. For example, median([5,2,8,6,9,10,1]) is 6, because there are three numbers less than 6 and three numbers greater than 6. Note that the median is not the same as the average. If there are an even number of elements in the array, such as [4,2,3,6], then the median should have one more element greater than it, so median([4,2,3,6]) should return 3. Write the median function. You may also write other functions first that are called from median. ----- Don't forget: for each function, write at least two different functions calls to test that it works.