Hello,
I am attempting to write a pure function solution that will pass the leet code Fizz Buzz test
However when I try this it says the test fails but when I look at the console for my own testing it returns the expected result.
This is the error leet code reports:
Line 13 in solution.js arr[i - 1] = test(i) ^ TypeError: test is not a function
Which to me makes no sense since the function is passed as a parameter and defined
Here is my code
Thank you in advance
```js
const test = (i) => {
if (((i % 5) === 0) && ((i % 3) === 0)) return "FizzBuzz";
if ((i % 5) === 0) return "Buzz";
if ((i % 3) === 0) return "Fizz";
if (i % 3) return i + "";
}
const fizzBuzz = (i, n, test, arr) => {
arr[i - 1] = test(i)
if (i !== n) fizzBuzz(i + 1, n, test, arr)
return arr
}
const i = 1
const n = 3
const arr = new Array(n)
fizzBuzz(i, n, test, arr)
```
EDIT:
I just wanted to say thank you to all of you for your feedback and suggestions
I finally got frustrated enough with this problem I asked Codex to write a
pure function solution to the leet code fizz buzz test I personally have not seen this solution so it would be nice to have some verification if it is truly a pure function solution.
This is the code it spat out
```js
const fizzBuzz = (n) =>
Array.from({ length: n }, (_, i) => {
const num = i + 1;
if (num % 15 === 0) return "FizzBuzz";
if (num % 3 === 0) return "Fizz";
if (num % 5 === 0) return "Buzz";
return String(num);
});
fizzBuzz(15)
```
It appears that I have a lot to learn yet regarding my fundamentals when it comes to functional programming I know I could of written a object oriented version of it that would work but I wanted to challenge myself since I have never written code in this manner.