Post History
JavaScript (Node.js), 74 70 bytes Works for any number of dimensions. f=(a,z=[])=>a.map?.((b,c)=>z.push(...f(b).map(a=>[c,...a])))?z:a?[z]:z Try it online! (TIO uses an old version ...
Answer
#4: Post edited
- # [JavaScript (Node.js)], <del>74</del> 70 bytes
- <!-- language-all: lang-javascript -->
- f=(a,z=[])=>a.map?.((b,c)=>z.push(...f(b).map(a=>[c,...a])))?z:a?[z]:z
- [Try it online!](https://tio.run/##VVCxbsMgEN39FYyHRBGsjoj3DunQETEQ16SuEmMZEin8vAOYxraQ7h7v3b2D@9MP7dqpH/3HYH@6eTYCNAlCKiyOmt702FCAM2njNdDx7n6BUmrgjJMGWhxlSyKjFca4CbVuZFB1mFs7OI9857xDAskKIUZi4ClIlSNbEi@JMMLzKfyO2VKKvDPbiv8NWecFMcI2PQlFuPSlQUVnxYuvrtlXyveTcuWCVm7vuZ20Vu7d02PVoaqMnWDdEbJm2RWOP0m0vXb0ai/w@f11os5P/XDpzRMMpKq46cP8Ag) (TIO uses an old version of Node.js that does not support the `?.` operator, but you can try the [74 bytes](https://tio.run/##VVCxjsMgDN3zFYxYogjWVmn3DnfDjYjBJVClakMVuEr9@hwQrkmEZD89Pz8b3/CFwYz9M@4G39lpci22R@QPfJ6Qj7b7NZbSCzOsg/Z44cYPBiN11EDW0CRWHeOcowZgSsMeT0ppvVd6StoQSbQhBtIS1RAiWAoyB6VLFHOSNTHBZHmV3zBrSrNPFuvif0Opy4oEE6uejBKc@/KgWhfVSy6uxVepz0pFOaOF23quJy3KrXteVh@axvmRLjci3s23gvSTTPu75Xd/peef7y8e4tgP19690@mzCgAO0x8) solution)
- [JavaScript (Node.js)]: https://nodejs.org
- # [JavaScript (Node.js)], <del>74</del> 70 bytes
- Works for any number of dimensions.
- <!-- language-all: lang-javascript -->
- f=(a,z=[])=>a.map?.((b,c)=>z.push(...f(b).map(a=>[c,...a])))?z:a?[z]:z
- [Try it online!](https://tio.run/##VVCxbsMgEN39FYyHRBGsjoj3DunQETEQ16SuEmMZEin8vAOYxraQ7h7v3b2D@9MP7dqpH/3HYH@6eTYCNAlCKiyOmt702FCAM2njNdDx7n6BUmrgjJMGWhxlSyKjFca4CbVuZFB1mFs7OI9857xDAskKIUZi4ClIlSNbEi@JMMLzKfyO2VKKvDPbiv8NWecFMcI2PQlFuPSlQUVnxYuvrtlXyveTcuWCVm7vuZ20Vu7d02PVoaqMnWDdEbJm2RWOP0m0vXb0ai/w@f11os5P/XDpzRMMpKq46cP8Ag) (TIO uses an old version of Node.js that does not support the `?.` operator, but you can try the [74 bytes](https://tio.run/##VVCxjsMgDN3zFYxYogjWVmn3DnfDjYjBJVClakMVuEr9@hwQrkmEZD89Pz8b3/CFwYz9M@4G39lpci22R@QPfJ6Qj7b7NZbSCzOsg/Z44cYPBiN11EDW0CRWHeOcowZgSsMeT0ppvVd6StoQSbQhBtIS1RAiWAoyB6VLFHOSNTHBZHmV3zBrSrNPFuvif0Opy4oEE6uejBKc@/KgWhfVSy6uxVepz0pFOaOF23quJy3KrXteVh@axvmRLjci3s23gvSTTPu75Xd/peef7y8e4tgP19690@mzCgAO0x8) solution)
- [JavaScript (Node.js)]: https://nodejs.org
#3: Post edited
# [JavaScript (Node.js)], 74 bytesWorks for any number of dimensions.- <!-- language-all: lang-javascript -->
f=a=>a.map?a.reduce((b,c,d)=>b.concat(f(c).map(a=>[d,...a])),[]):a?[[]]:[][Try it online!][TIO-kjpjo3sd][JavaScript (Node.js)]: https://nodejs.org[TIO-kjpjo3sd]: https://tio.run/##VVCxjsMgDN3zFYxYogjWVmn3DnfDjYjBJVClakMVuEr9@hwQrkmEZD89Pz8b3/CFwYz9M@4G39lpci22R@QPfJ6Qj7b7NZbSCzOsg/Z44cYPBiN11EDW0CRWHeOcowZgSsMeT0ppvVd6StoQSbQhBtIS1RAiWAoyB6VLFHOSNTHBZHmV3zBrSrNPFuvif0Opy4oEE6uejBKc@/KgWhfVSy6uxVepz0pFOaOF23quJy3KrXteVh@axvmRLjci3s23gvSTTPu75Xd/peef7y8e4tgP19690@mzCgAO0x8 "JavaScript (Node.js) – Try It Online"
- # [JavaScript (Node.js)], <del>74</del> 70 bytes
- <!-- language-all: lang-javascript -->
- f=(a,z=[])=>a.map?.((b,c)=>z.push(...f(b).map(a=>[c,...a])))?z:a?[z]:z
- [Try it online!](https://tio.run/##VVCxbsMgEN39FYyHRBGsjoj3DunQETEQ16SuEmMZEin8vAOYxraQ7h7v3b2D@9MP7dqpH/3HYH@6eTYCNAlCKiyOmt702FCAM2njNdDx7n6BUmrgjJMGWhxlSyKjFca4CbVuZFB1mFs7OI9857xDAskKIUZi4ClIlSNbEi@JMMLzKfyO2VKKvDPbiv8NWecFMcI2PQlFuPSlQUVnxYuvrtlXyveTcuWCVm7vuZ20Vu7d02PVoaqMnWDdEbJm2RWOP0m0vXb0ai/w@f11os5P/XDpzRMMpKq46cP8Ag) (TIO uses an old version of Node.js that does not support the `?.` operator, but you can try the [74 bytes](https://tio.run/##VVCxjsMgDN3zFYxYogjWVmn3DnfDjYjBJVClakMVuEr9@hwQrkmEZD89Pz8b3/CFwYz9M@4G39lpci22R@QPfJ6Qj7b7NZbSCzOsg/Z44cYPBiN11EDW0CRWHeOcowZgSsMeT0ppvVd6StoQSbQhBtIS1RAiWAoyB6VLFHOSNTHBZHmV3zBrSrNPFuvif0Opy4oEE6uejBKc@/KgWhfVSy6uxVepz0pFOaOF23quJy3KrXteVh@axvmRLjci3s23gvSTTPu75Xd/peef7y8e4tgP19690@mzCgAO0x8) solution)
- [JavaScript (Node.js)]: https://nodejs.org
#2: Post edited
- # [JavaScript (Node.js)], 74 bytes
- Works for any number of dimensions.
- <!-- language-all: lang-javascript -->
f=a=>a.map?a.reduce((b,c,d)=>b.concat(f(c).map(a=>[d,...a])),m=[]):a?[m]:m[Try it online!][TIO-kjpjcqsm]- [JavaScript (Node.js)]: https://nodejs.org
[TIO-kjpjcqsm]: https://tio.run/##jY8xD4MgEIX3/hJIrgRXG3Xv0A4dCcOJaGxEjNom/fUWRasujWG4F@5778ET39iptmz6c20zPQx5hFGMzGCTIGt19lKakBQUZDSKU6ZsrbAnOVF0ZIiDRQaMMZSUgomEpCEmwsjQDI7tbKVZZQtyfdxvrOvbsi7K/OP8IgAOwXS4s9LL6T@@448bJPwmP25dyiZ3MCsOfJM4Kid9qstd9nxuCtbOsRWEWB7vSa/Wu33mtmkl9@n@K8MX "JavaScript (Node.js) – Try It Online"
- # [JavaScript (Node.js)], 74 bytes
- Works for any number of dimensions.
- <!-- language-all: lang-javascript -->
- f=a=>a.map?a.reduce((b,c,d)=>b.concat(f(c).map(a=>[d,...a])),[]):a?[[]]:[]
- [Try it online!][TIO-kjpjo3sd]
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-kjpjo3sd]: https://tio.run/##VVCxjsMgDN3zFYxYogjWVmn3DnfDjYjBJVClakMVuEr9@hwQrkmEZD89Pz8b3/CFwYz9M@4G39lpci22R@QPfJ6Qj7b7NZbSCzOsg/Z44cYPBiN11EDW0CRWHeOcowZgSsMeT0ppvVd6StoQSbQhBtIS1RAiWAoyB6VLFHOSNTHBZHmV3zBrSrNPFuvif0Opy4oEE6uejBKc@/KgWhfVSy6uxVepz0pFOaOF23quJy3KrXteVh@axvmRLjci3s23gvSTTPu75Xd/peef7y8e4tgP19690@mzCgAO0x8 "JavaScript (Node.js) – Try It Online"
#1: Initial revision
# [JavaScript (Node.js)], 74 bytes Works for any number of dimensions. <!-- language-all: lang-javascript --> f=a=>a.map?a.reduce((b,c,d)=>b.concat(f(c).map(a=>[d,...a])),m=[]):a?[m]:m [Try it online!][TIO-kjpjcqsm] [JavaScript (Node.js)]: https://nodejs.org [TIO-kjpjcqsm]: https://tio.run/##jY8xD4MgEIX3/hJIrgRXG3Xv0A4dCcOJaGxEjNom/fUWRasujWG4F@5778ET39iptmz6c20zPQx5hFGMzGCTIGt19lKakBQUZDSKU6ZsrbAnOVF0ZIiDRQaMMZSUgomEpCEmwsjQDI7tbKVZZQtyfdxvrOvbsi7K/OP8IgAOwXS4s9LL6T@@448bJPwmP25dyiZ3MCsOfJM4Kid9qstd9nxuCtbOsRWEWB7vSa/Wu33mtmkl9@n@K8MX "JavaScript (Node.js) – Try It Online"