DEV Community

Cover image for Day 7 Challenge
Hello Dev World Blog
Hello Dev World Blog

Posted on • Originally published at hellodevworld.com

Day 7 Challenge

Create a function that accepts an array and an item and counts the number of times that item shows up in the array. Do not ignore capitalization, punctuation, or spaces.

Examples:

    itemCounter(["hello", [["Hello", "hello"], [["Hello"]], "Hello", "world"]], "hello"); // 2

    itemCounter([["A", "A", "A", "A", "A", "a"],
        ["a", "A", "A", "A", "A", "A"],
        ["A", "a", "A", "A", "A", "A"],
        ["A", "A", "A", "a", "A", "A"]], "a"); // 4

    itemCounter([1, 2, [3], [4, 5], [4, [[6, 7], 4]]], 4); // 3

    itemCounter([1, 2, [3, 11], [4, 5], [4, [[6, 7], 4]]], 10) // 0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)