I have been searching, but I couldn't find any information on what I am about to ask. As a beginner and student learning JavaScript, I have a question. I am familiar with how to check if a number is prime or not. Here is my current challenge:
numbers([
[5, 7, 10],
[8, 2, 3],
[44, 50, 22]
])
expected output:
[
['#', '#', 10],
[8, '#', '#'],
[44, 50, 22]
]
What I need is this: if there is a prime number in a multidimensional array, it should be replaced with #
, otherwise leave it unchanged. The task specifically prohibits the use of built-in functions such as .indexOf
, .include
, .findIndex
, .reduce
, .map
, .filter
, adding new parameters, or regex. So far, here's what I've attempted:
function multidimensionalPrimesChecker(numbers)
{
for (var i = 0 ; i < numbers.length ; i++)
{
for (var j = 0 ; j < numbers[i].length ; j++)
{
if (numbers[i][j] % i === 0)
{
return false;
}
}
}
}
I am currently stuck and unsure how to proceed with this problem. Any help would be greatly appreciated. Thank you for your kindness.