Array practice (part 1)

Complete the following exercises to improve your understanding of javascript functions!

Tests for each of these have been written and can be found in this repo. Fork and git clone it to make use of the tests! Detailed instructions in the test repo.

  1. 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
  2. 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)'
  3. 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]
  4. 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]
  5. Write a JavaScript function to merge two arrays and removes all duplicates elements.

    • Sample input: merge_array([1, 2, 3], [2, 30, 1])
    • Sample output: [3, 2, 30, 1]

results matching ""

    No results matching ""