# Map values to any multidimensional array [closed]

## Codegolf challenge - mapping values in a multidimensional array

[
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]


This 2D array is sick of being so false, and wants to find the truth about life, once and for all. Your task is to write a map function to act as a highway to all the values in this array.

An example implementation of this super function would be if the above array is defined as arr below:

arr.multimap(x => {
return 1;
}


Which would result in the array being:

[
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]


This is a 2D number example, yours has to work in any dimension, and not be dimensionally-bias.

## The rules

• Must work in any type of dimensional array (1D, 2D, 3D, etc..)
• Least bytes, wins!
• Must only have one callback function which accounts for any level of dimensional interaction
• Meta-languages get fewer points
• Can simply be a function which applies the logic to an array given
• Can be any arbitrary initial value, as long as you can replace it on-command
• Comments are not for extended discussion. This conversation has been moved to chat. Apr 23, 2019 at 21:54

# JavaScript (Node.js), 3527 17 bytes

-18 thanks to @Arnauld and @Shaggy

f=a=>a?a.map(f):1

console.log(f([
[0, 0, 0],
[0, [0, 0, 0], 0],
[[0, 0, [0]], 0, 0]
]))

• @Arnauld lol, you are right. Thanks! Apr 23, 2019 at 12:59
• 21 bytes Apr 23, 2019 at 13:20
• @Arnauld: Or 17 bytes Apr 23, 2019 at 16:36
• @Shaggy Yup, but it's still unclear if the initial values are guaranteed to be falsy (see the last rule). Apr 23, 2019 at 16:42

# Jelly, 1 byte

‘


Try it online!

Replaces n with n + 1.

Because Jelly things.

Note that [x] displays as x in Jelly (single-element lists don't show as lists); the internal data is still a single-element list. You can make it show using Python's str: Try it online!.

# Perl 6, 4 bytes

!<<*


Try it online!

Replaces 0s with True. Extremely short for a non-esolang.

   *  # From the input
!     # Boolean not
<<   # Each element recursively


# Python 2, 2926 25 bytes

-3 bytes thanks to @JonathanAllan

-1 byte thanks to @JoKing

f=lambda a:a<1or map(f,a)


Replaces 0 with True

Try it online!

• Python 2, 26 Apr 23, 2019 at 17:42
• @Neil the f= is necessary for a recursive function. Apr 23, 2019 at 17:43
• <[] can be <1
– Jo King
Apr 24, 2019 at 11:43

# Japt, 6 bytes

?¡ßX:1


Try it

¬Íª¡ßX


Try it

# JavaScript, 36 bytes

t=>JSON.stringify(t).replace(/0/g,1)


Try it online!