Question: **I wanted to create my own NFT collection so I bought a course called "The Complete NFT Web Development Course - Zero To Expert
". In that course you need to use truffle. I installed all what I sopposed to need but when I try to type truffle init it gives me an error. I used npm install also in this process and it gaves me an error related to react, but I don't think that it's the problem. I have a package.json downloaded from the github repositorie that the teacher have.**

**Versions:**

npm: '8.3.1',
node: '16.14.0'
Windows 10

**Error:**
truffle init
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\Usuario\AppData\Roaming\npm\node\_modules\truffle\build\cli.bundled.js'
[90m at Function.Module.\_resolveFilename (node:internal/modules/cjs/loader:933:15)[39m
[90m at Function.Module.\_load (node:internal/modules/cjs/loader:778:27)[39m
[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run\_main:77:12)[39m
[90m at node:internal/main/run\_main\_module:17:47[39m {
code: [32m'MODULE\_NOT\_FOUND'[39m,
requireStack: []
}

Answer: 
One more version, based on Alan Thompson's solution:

```
(defn flat [data]
  (reduce (fn [result e]
            (if (not (sequential? e))
              (conj result e)
              (into result (flat e))))
          [] data))

```

Tests:

```
(clojure.test/are [result arg]
  (= result (flat arg))
  [1 2 3] [1 2 3]
  [1 2 3] [1 [2 3]]
  [1 2 3] [1 [2 [3]]]
  [0 1 2 3 4 5 6 7] [[0] [1 2 3] [4 5 [6 7]]])
=> true

```
Here is an alternate version that may be a bit more straightforward:

```
(ns tst.demo.core
  (:use tupelo.core tupelo.test))

(defn flatten
  [data]
  (loop [result []
         items  data]
    (if (empty? items)
      result
      (let [item       (first items)
            items-next (rest items)]
        (if (not (sequential? item))
          (recur
            (conj result item)
            items-next)
          (recur
            (into result (flatten item))
            items-next))))))

(dotest
  (is= (flatten [1 2 3]) [1 2 3])
  (is= (flatten [1 [2 3]]) [1 2 3])
  (is= (flatten [1 [2 [3]]]) [1 2 3])
  (is= (flatten [[0] [1 2 3] [4 5 [6 7]]]) [0 1 2 3 4 5 6 7])

  ; Cannot flatten a scalar value - we don't want (flatten 3) => [3]
  (throws? (flatten 3)))

```

Note that we avoid tricks like wrapping every scalar value in a list, so we don't get the non-intuitive result `(flatten 3) => [3]`.

---

Build using [my favorite template project](https://github.com/io-tupelo/clj-template).