Complete the following exercises to improve your understanding of arrays in javascript!
- In
main.js
, define the functions listed below and test that it works by running it againsthelper.test(yourFunction(), yourExpectedValue)
. - As opposed to manually checking the output every time you run the function, we've written a helper method (
helper.test()
) to help you check whether your code produces the expected output. - For each function, add 1-2 more test cases to confirm that your function really works.
- Write a JavaScript function which accept a number as input and insert dashes (-) between each two even numbers.
- Sample input: 025486
- Sample output: 0-254-8-6
- Write a Javascript function to find the most frequent item of an array. It should return a string denoting the item and the number of times it occurs in the array.
- Sample input: [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
- Sample output : 'a (5 times)'
- Write a Javascript function to remove duplicate items from an array (ignore case sensitivity).
- Sample input : [1, 'a', 'A', 'b', 2, 2]
- Sample output: [1, 'a', 'b', 2]
- Write a Javascript function to compute the union of two arrays.
- Sample input: union([1, 2, 3], [100, 2, 1, 10])
- Sample output: [1, 2, 3, 10, 100]
- Write a JavaScript function to merge two arrays and removes all duplicates elements.
- Sample input: mergeArray([1, 2, 3], [2, 30, 1])
- Sample output: [3, 2, 30, 1]