DEV Community

loading...
Cover image for Day 7 Challenge

Day 7 Challenge

hellodevworldblog profile image Hello Dev World Blog Originally published at hellodevworld.com ・1 min read

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

Discussion (0)

pic
Editor guide