Question: Use Ruby programming for the following: An int-array is an array of zero or more int-expressions, where an int-expression is an integer or an int-array.

Use Ruby programming for the following:

An int-array is an array of zero or more int-expressions, where an int-expression is an integer or an int-array. Informally, an int-array is an array of integers that can nest to any depth. Write a function count_occurrences_rec(a, i) that counts the number of times that the integer i occurs in the int-array a.

>> a

=> [1, [1, 2], [[[1, 1], 1]]]

>> count_occurrences_rec(a, 1)

5

>> count_occurrences_rec(a, 2)

1

>> count_occurrences_rec(a, 3)

0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!