22
3
To neutralize data, recursively replace all numbers (not digits!) with zeros and all characters (not strings!) with spaces.
You must accept any single number, character, or string, or possibly recursive array* of mixed numeric/character data that your language can handle. For example, you must accept actual strings (and not restrict your input to lists of single characters) if your language can handle such.
If your language contains a built-in which does all or most of this task, I would appreciate an additional alternative version without it.
The shortest submission in each language is a winner, and will receive an upvote from me.
Sample cases
""
→""
7
→0
123.456
→0
"X"
→" "
" "
→" "
"Yo!"
→" "
[]
→[]
[-1.2E3]
→[0]
["Hey"]
→[" "]
["H","e","y"]
→[" "," "," "]
["R",2,"D",2]
→[" ",0," ",0]
["C","3","P",0]
→[" "," "," ",0]
["THX",[1138]]
→[" ",[0]]
["T","H","X",[1138]]
→[" "," "," ",[0]]
[[["H"],"e",1,1,0],[[-3],"arth"]]
→[[[" "]," ",0,0,0],[[0]," "]]
* If your language has several types which can equally well represent arrays like the above examples, you may chose to support only one. Two entries can both win, even though they are using the same language, by each going with a different data type.
What if our language doesn't distinguish between characters and length-1 strings? – xnor – 2017-01-16T09:48:05.170
@xnor AFAICT the effect would be the same. – Adám – 2017-01-16T09:52:26.237
Oh, I see that now from the test cases, but it wasn't clear to me that meant to take every string element and replace each of its characters with spaces. Actually, I didn't interpret that the replacements have to be done recursively at all. The spec talks about neutralizing an array, but it looks like you want single elements not in an array to be acted on as well? – xnor – 2017-01-16T09:54:37.560
@xnor Correct. Feel free to edit the question to better reflect this. – Adám – 2017-01-16T09:58:04.087
Let us continue this discussion in chat.
– Adám – 2017-01-16T10:53:33.627What if our language doesn't distinguish between numbers and strings of digits? – DLosc – 2017-01-16T18:54:00.267
Also, what about languages that don't have a string or character data type? Can they just replace the numbers, or are they disallowed for this challenge? – DLosc – 2017-01-16T18:55:23.167
@DLosc Not disallowed, but rather pointless. I suppose this either isn't a production grade language or is a very old language. Feel free to submit anyway. – Adám – 2017-01-16T19:03:36.870