repl.it
@haideralsh/

jsRecursion

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function hasNum(num, arr) {
    hasNumber = false

    for (let element of arr) {
        if (Array.isArray(element)) {
            hasNum(num, element)
        } else {
            if (element === num) { hasNumber = true }
        }
    }

    return hasNumber
}

console.log(hasNum(2, [ 1, 3, [2] ]))