[Question]
  [
Take an array which consists of positive integers or arrays, output if it only contains `2`s.
Output should be a truthy or falsey value (Sorry if this destroys answers)
## Truthy Test Cases
```
[2]
[2,2]
[[2],[2,2],2]
[]
[[],[]]
```
## Falsey Test Cases
```
[1]
[22]
[2,2,2,1]
[[1,2],2]
```
[Standard Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) Are forbidden.
[Default IO](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) rules apply.
Code-golf, Fewest bytes wins!
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~43~~ 40 bytes
```
f=lambda l:l>=[]and all(map(f,l))or l==2
```
[Try it online!](https://tio.run/nexus/python2#VY5BCsQgDEXX9RShKwVnQJcFexFxkaEIheiUkl3p2a21MDgJfPJfwiclOsL0WRBootn5gHkBJJIJNxk1KfXdgZyzhcGBF3DX4G3Qv1F35l48pIMViaahssGbpvY/orbpYswT0XwQItYnGNYMPDW07WtmGI8TXjMc5/iuBwlZsoYoWalyAQ "Python 2 – TIO Nexus")
---
At time of posting this answer, it was still allowed per [this](https://codegolf.meta.stackexchange.com/a/11908/64121) meta consensus to output via throwing an error / not throwing an error. Therefore this answer at 26 bytes was valid:
```
f=lambda l:l==2or map(f,l)
```
[Try it online!](https://tio.run/nexus/python2#@59mm5OYm5SSqJBjlWNra5RfpJCbWKCRppOj@b9EwVYhmksBBDijjWJ14EwdJA5IAiKCJAgU4gKTsUAxzmhDMGmEagQQGiIZYwgxAsyP5eJKAzqkRCEzT6HECihUUlRpBZYpKMrMK1FQqq5V0LVTqK5V0gOqy00s0SjRUUjTKNHUBCpKrUhOLSjBotw1KMg/CKFD8z8A "Python 2 – TIO Nexus")
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~43~~ 33 bytes
I smell... ***recursion***.
Thanks to *Emigna* and *Leaky Nun* for saving 10 bytes!
### Code
```
a([]).
a([X|T]):-(X=2;a(X)),a(T).
```
[Try it online!](https://tio.run/nexus/prolog-swi#@5@oER2rqccFpCJqQmI1rXQ1ImyNrBM1IjQ1dRI1QjT1/v8HykUbxepEG@kASSOgagA "Prolog (SWI) – TIO Nexus") or [Verify all test cases!](https://tio.run/nexus/prolog-swi#@5@oER2rqccFpCJqQmI1rXQ1ImyNrBM1IjQ1dRI1QjR1FPX@/wfKGkFVGenAWEAhHTAXLgKTAIrHQtmGMG1I@oEQJhxtCNcPAA)
### Explanation:
For non-Prolog users, a list is formatted in the following way: `[Head | Tail]`.
The `Head` is the first element of the list, and tail is the remaining list. [Test it here!](https://tio.run/nexus/prolog-swi#@5@RmpgSX5KYmROfWlFSlJhckl@kEe0BFFSoUQgBCsfqKIB4OmCOpt7//1g1GOooGOkoGOsomKCpBwA). An important case here is that the **tail** of a list with 1 element is equal to `[]`. You can [test that here](https://tio.run/nexus/prolog-swi#@5@RmpgSX5KYmROfWlFSlJhckl@kEe0BFFSoUQgBCsfqKIB4OmCOpt7//1g1GKIpAwA).
```
% State that an empty array is truthy.
a([]).
% If the list is not empty (covered by the previous line), we need to check
% whether the Head is equal to 2 or whether the head is truthy.
% After that, we only need to check if the remaining list is truthy.
a([Head | Tail]) :- (Head = 2; a(Head)), a(Tail).
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
F;2E
```
[Try it online!](https://tio.run/nexus/jelly#@@9mbeT6/3D7o6Y1//9Hc3FGG8XqgEgdCA3iQjgQPkQQKBYLZhnCFAMhhB1tCFHMFQsA "Jelly – TIO Nexus")
## How it works
```
F;2E
F    flatten
 ;2  append 2
   E all elements are equal
```
[Answer]
# Octave, 13 bytes
```
@(x)~any(x-2)
```
[**Verify all test cases.**](https://tio.run/nexus/octave#S7PV09P776BRoVmXmFepUaFrpPk/JbO4QEM9pKg01UpdkytNI9ooFkLpQBlAAR0wDyYAFQaKxgKZEP1uiTnFMAMMoQYgDAJCqGC0IdSg/wA)
This is an anonymous function taking one input argument, `x`. It subtracts `2` from all elements, checks if there are any non-zero elements. It negates the output to get `true` for cases where all values are zero.
This works because `x-2` works for matrices of all sizes, including the empty matrix, `[]`.
`x-2` would be sufficient if there couldn't be empty matrices in the input.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 3 bytes
```
2=p
```
[Try it online!](https://tio.run/nexus/matl#@29kW/D/f3S0UaxOtKEOkDSKBQA "MATL – TIO Nexus")
Technically, this could just be
```
2=
```
Since an array containing any zero elements is falsy, but this seems cheap.
[Answer]
# [Mathics](http://mathics.github.io/), 28 bytes
```
Select[Flatten@#,#!=2&]=={}&
```
[Try it online!](https://tio.run/nexus/mathics#S7P9H5yak5pcEu2Wk1hSkprnoKyjrGhrpBZra1tdq/Y/oCgzr8QhzaHaSAeIjGqBiAsuVl2rU12LxAeqMa6t/Q8A "Mathics – TIO Nexus")
[Answer]
## [Retina](https://github.com/m-ender/retina), ~~13~~ 10 bytes
*Thanks to Kritixi Lithos for saving 3 bytes.*
```
\W|\b2
^$
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/gfE14Tk2TExRWn8v9/tFEsV7SRDogEMnXATDAPJADkxwJpQ5ASqDogBHGjDSHqAA "Retina – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
˜YQP
```
[Try it online!](https://tio.run/nexus/05ab1e#@396TmRgwP//0dFGsTrRRjpA0igWAA "05AB1E – TIO Nexus")
**Explanation**
```
˜      # flatten list
 YQ    # check each element for equality to 2
   P   # product of list
```
[Answer]
# JavaScript (ES6), ~~22~~ ~~19~~ ~~23~~ 22 bytes
```
a=>!/[^2,]|22/.test(a)
```
---
## Test it
```
f=
a=>!/[^2,]|22/.test(a)
console.log(" "+f([2])+": "+JSON.stringify([2]))
console.log(" "+f([2,2])+": "+JSON.stringify([2,2]))
console.log(" "+f([[2],[2,2],2])+": "+JSON.stringify([[2],[2,2],2]))
console.log(" "+f([])+": "+JSON.stringify([]))
console.log(" "+f([[],[]])+": "+JSON.stringify([[],[]]))
console.log(f([1])+": "+JSON.stringify([1]))
console.log(f([22])+": "+JSON.stringify([22]))
console.log(f([2,2,2,1])+": "+JSON.stringify([2,2,2,1]))
console.log(f([[1,2],2])+": "+JSON.stringify([[1,2],2]))
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 5 bytes
```
∧/2=∊
```
[Try it online!](https://tio.run/nexus/apl-dyalog#@@/4qG3Co47l@ka2jzq6/v93VDDiAmIwqfGoq8lIUwdMKQAZIBoo/Kh3DYTUgbAMIRqAEMQCKtIwBKk2AgA "APL (Dyalog Unicode) – TIO Nexus")
### Explanation
```
∧/                         Only
  2=                       2s are equal to
    ∊                      any of the elements in the enlisted form of the right argument
```
[Answer]
# Mathematica, 15 bytes
```
FreeQ[x_/;x!=2]
```
It also works in Mathics. [Try it online!](https://tio.run/nexus/mathics#S1OwVfjvVpSaGhhdEa9vXaFoaxT7P6AoM69EwUFLIU1B30GhutqoVkeh2kgHTIE4EDaYCxYCitSCGIZgdTDVQAgWqDaEqK79DwA)
[Answer]
# Mathematica, 24 bytes
```
Cases[t=Flatten@#,2]==t&
```
Pure function returning `True` or `False`. After `Flatten`ing the nested array and calling it `t`, `Cases[t,2]` returns the list of elements that match the "pattern" `2`, and `==t` checks whether that's the whole list.
# Mathematica, 29 bytes
```
(#//.{2->{},{{}..}->{}})=={}&
```
Not as short, but more fun. Starting from the input `#`, two replacement rules are applied until the result stops changing (`//.`): first, all `2`s are replaced by `{}`s; and then any list whose entries are all empty sets (`{{}..}`) are replaced (repeatedly) by empty sets. If the rest is an empty set (`=={}`), we win.
[Answer]
# [Haskell](https://www.haskell.org/), 36 bytes
An anonymous function, takes a `String` and returns a `Bool`.
Use as `(all((==2).fst).(reads=<<).scanr(:)[]) "[2,2,2,1]"`
```
all((==2).fst).(reads=<<).scanr(:)[]
```
[Try it online!](https://tio.run/nexus/haskell#LYpBCsMgEEX3PYWELmYwEeKyxFzEuhBrqWBscSw9vlUJA3/@@7zDhqRCKj5bV67fFEPyJA77gTstO3E@sWVnE@f0ev/AMUIUw6lO2RgBlJIonlRQQPb2QWrbUJCzKcMNtalVS3PRcu7Z6jzqoD40Nu2vXTm9dh31enp/ "Haskell – TIO Nexus")
# How it works
* Haskell doesn't have builtin mixed-type lists, so we take a string as argument.
* `scanr(:)[]` generates a list of all suffixes of the string.
* `(reads=<<)` tries to parse a number at the beginning of each suffix, combining the successes into a list of tuples `(n,restOfString)`.
* `all((==2).fst)` checks if all the parsed numbers are `2`.
[Answer]
# [Python 2](https://docs.python.org/2/), 38 bytes
```
lambda l:l.strip('[],2')==l*('22'in l)
```
[Try it online!](https://tio.run/nexus/python2#VY7RCoMwDEWf7VcEX9KOTrCPQvcjXcHOKQjVlZo38dtdrTBcApfkXHLJoJ@7d9Pr7cA3vloojoGjsVKh0NrfOCqF4wxe7AQaDIOjCqOs/I3yshzGSS4wIZbVJlaYOqv6j0hdX2LqMyLvlrHhE4Eg/UFNRp1bet1SW8U@eNf1HAEloshmiONMUK4b3B@wbmWVridHnCQM/LgUYv8C "Python 2 – TIO Nexus")
Takes in a string without spaces, outputs a bool.
Checks if removing all the characters `'[],2'` of `l` gives the empty string. Also checks that `22` is not a substring -- if it is, the input `l` is used in place of the empty string to compare to the result of removal, and that always fails.
[Answer]
# Ruby, ~~28~~ ~~23~~ 22 bytes - 5 bytes saved by G B
```
->x{x.flatten-[2]==[]}
```
Despite "flatten" being really long, it's still shorter than regex based solutions or recursive stuff that has to rescue errors in the base case. Ruby's built-in conflation of sets and arrays, however, is amazingly useful sometimes.
[Answer]
## JavaScript (ES6), 26 bytes
```
f=a=>a.map?a.every(f):a==2
```
### Test cases
```
f=a=>a.map?a.every(f):a==2
console.log(f([2]))
console.log(f([2,2]))
console.log(f([[2],[2,2],2]))
console.log(f([]))
console.log(f([[],[]]))
console.log(f([1]))
console.log(f([22]))
console.log(f([2,2,2,1]))
console.log(f([[1,2],2]))
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 4 bytes
```
2-a~
```
[Try it online!](https://tio.run/nexus/matl#@2@km1j3/3@0kQ4QxgIA "MATL – TIO Nexus")
**Breakdown:**
```
           % Implicit input
2-         % Push 2 to the stack, and subtract from input
  a        % Any non-zero elements?
    ~      % Negate to get true for cases where all elements are zero.
```
---
Well, [outgolfed](https://codegolf.stackexchange.com/a/120365/31516). But I'm keeping this, since I'm quite happy I managed this all on my own (even though the task is super simple).
[Answer]
# R, 28 bytes
```
function(x)!any(unlist(x)-2)
```
`unlist(x)` turns a (nested) list into a vector. Then `2` is subtracted from that vector. `any` converts (with a warning) numeric to logical and checks if there are any `TRUE`s. This is inverted with `!` and output.
This works with nested lists because `unlist` by default works recursively to unlist all list entries of the initial list.
This also works with empty lists, because `unlist(list())` becomes `numeric()`, an empty numerical vector. Coercion by `any` makes it `logical()`, which is interpreted as `FALSE` by `any`, and then reversed to `TRUE` by `!`.
[Answer]
# [Python 3](https://docs.python.org/3/), 55 bytes
No cheating. Uses nested list as input.
```
f=lambda a:all(type(x)!=int and f(x)for x in a if x!=2)
```
[Try it online!](https://tio.run/nexus/python3#PY3BCoAgEETP@RXbTaGLHQW/RDxsmCCYiXSwrzdtKRZm5w0D07yOeGwOARXGyK8777yKWYd0ASYHvpM/C1QICRCChzrrVbQ/M2wyq12GLvQHEhBT2DP7OvmV@5E3ksrMKjbl0qf5mBXtAQ "Python 3 – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
F=2Ạ
```
[Try it online!](https://tio.run/nexus/jelly#@@9ma/Rw14L///9HRxvF6ihEG@kogGijWAA "Jelly – TIO Nexus")
Slightly different than Leaky's algorithm.
Explanation:
```
F=2Ạ
F    Flatten
 =2  Check if equal to 2 (vectorizes)
   Ạ Check if there isn't any falsey value
```
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~14~~ 11 bytes
```
^(\W|2\b)+$
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/gfpxETXmMUk6SprfL/f7RRLFe0kQ6IBDJ1wEwwDyQA5McCaUOIEpCoCYQJhCDBaEOIagA "Retina – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
2‚˜Ë
```
[Try it online!](https://tio.run/nexus/05ab1e#@2/0qGHW6TmHu///j442itWJNtIBkkaxAA "05AB1E – TIO Nexus")
[Answer]
## JavaScript (ES6), ~~53~~ ~~50~~ 48 bytes
```
_=>(_+"").split`,`.map(c=>!c?2:c).every(c=>c==2)
```
*Saved 5 bytes, thanks to @Shaggy!*
### Test Cases :
```
let f =
_=>(_+"").split`,`.map(c=>!c?2:c).every(c=>c==2)
console.log(f([2]))
console.log(f([2,2]))
console.log(f([[2],[2,2],2]))
console.log(f([]))
console.log(f([[],[]]))
console.log(f([1]))
console.log(f([22]))
console.log(f([2,2,2,1]))
console.log(f([[1,2],2]))
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
˜DOsg·Q
```
[Try it online!](https://tio.run/nexus/05ab1e#@396jot/cfqh7YH//0cb6UBhLAA "05AB1E – TIO Nexus") or [Try All Tests!](https://tio.run/nexus/05ab1e#K6v8f3qOi39x@qHtgf8rlQ7vt1JQstf5Hx1tFKsTbaQDIhFMEAMkAKKA2BAkDpUEQhA32hCiLhYA "05AB1E – TIO Nexus")
```
˜D      # Flatten and duplicate
  O     # Sum one copy
   sg·  # Get double the length of the other copy
      Q # Check if they are equal
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 21 bytes
```
->x{x*?!!~/[^2!]|22/}
```
Using a regex is actually shorter, because joining an array also flattens it.
## How it works
```
->x{
    x*?!                -> Join array using an exclamation mark
        !~              -> String does not contain
          /[^2!]        -> characters different from '2' or '!'
                |       -> or
                 22/    -> '2' repeated at least twice
                    }
```
[Try it online!](https://tio.run/nexus/ruby#S7P9r2tXUV2hZa@jWKcfHWekE1tjZKRf@79AIS062ig2lgvMgNGGMIYRUOo/AA "Ruby – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
2ṁ⁼
```
[Try it online!](https://tio.run/##y0rNyan8/9/o4c7GR417/h9uf9S0Bojc//@PjuZSUIg2itUBUzpQBkgAwoMKQIWBorGxXApACsQ1hOpC6AZCqGC0IUx3bCwA "Jelly – Try It Online")
### How it works
```
2ṁ⁼  Main link. Argument: A (array)
2ṁ   Mold 2 like A. This replaces each number in A by 2.
  ⁼  Test if the result is equal to A.
```
[Answer]
# Java 8, ~~126~~ ~~55~~ 27 bytes
```
s->s.matches("(\\W|2\\b)+")
```
Port of [*@KritixiLithos*'s amazing Retina answer](https://codegolf.stackexchange.com/a/120356/52210), excluding the `^...$`, since `String#matches` always matches the entire String and adds the `^...$` implicitly.
-2 bytes thanks to @Jakob for reminding me of `^...$` isn't necessary for `String#matches`.
[Try it here.](https://tio.run/##jZCxDoIwEIZ3nuLC1EYggZXoG8ji4AAMR6lahJbYamKUZ8eCLC7YNLmkue@@P3cNPjBUPZdNfR1Zi1rDHoV8eQBCGn47IeOQTV@ASqmWowRGDuYm5Bk0TW1j8GzRBo1gkIGELYw63OmoQ8MuXBOfFMXxnRRFRTc@HdMJ7@9Va/Fl6qFEDZ2NXcR5CUi/mYenNryL1N1EvW2ZVhIZMeLnSenTOX6NCVwoqwpm1Il2EVpfucr9M8QuyzlewD4XXR7/XGDwhvED)
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 4 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
Ḟ2=p
```
[Try it online!](https://Not-Thonnu.github.io/run#P2hlYWRlcj0mY29kZT0lRTElQjglOUUyJTNEcCZmb290ZXI9JmlucHV0PSU1QjIlNUQlMjAtJTNFJTIwMSUwQSU1QjIlMkMyJTVEJTIwLSUzRSUyMDElMEElNUIlNUIyJTVEJTJDJTVCMiUyQzIlNUQlMkMyJTVEJTIwLSUzRSUyMDElMEElNUIlNUQlMjAtJTNFJTIwMSUwQSU1QiU1QiU1RCUyQyU1QiU1RCU1RCUyMC0lM0UlMjAxJTBBJTVCMSU1RCUyMC0lM0UlMjAwJTBBJTVCMjIlNUQlMjAtJTNFJTIwMCUwQSU1QjIlMkMyJTJDMiUyQzElNUQlMjAtJTNFJTIwMCUwQSU1QiU1QjElMkMyJTVEJTJDMiU1RCUyMC0lM0UlMjAwJmZsYWdzPUM=)
#### Explanation
```
Ḟ2=p  # Implicit input
Ḟ     # Flatten the list
 2=   # Check for == 2
   p  # All are true?
      # Implicit output
```
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata) + `-e`, 3 bytes
```
2-ž
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFNtJJurpKOgpJuqlLsgqWlJWm6FkuMdI_uW1KclFwMFVhw0z7aKJYr2kgHRAKZOmAmmAcSAPJjgbQhSAlUHRCCuNGGEHUQcwA)
```
2-      Minus 2
  ž     Check if all elements are zero
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~13~~ 10 bytes
```
2#2&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73@j9hO3KQGyk9j@gKDOvJFpZ1y7NQTlWrS44OTGvrpqr2qhWB0jogCkQB8IGc8FCQJFaIIOr2hCsEKYcCMEC1YYQ5Vy1/wE "Wolfram Language (Mathematica) – Try It Online")
`` is `\[VectorLessEqual]`.
]