(searchNum, ar, output = (v) => console.log(v))
| 7 | * @see https://en.wikipedia.org/wiki/Linear_search |
| 8 | */ |
| 9 | function SearchArray(searchNum, ar, output = (v) => console.log(v)) { |
| 10 | const position = Search(ar, searchNum) |
| 11 | if (position !== -1) { |
| 12 | output('The element was found at ' + (position + 1)) |
| 13 | } else { |
| 14 | output('The element not found') |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | // Search “theArray” for the specified “key” value |
| 19 | function Search(theArray, key) { |