Repository navigation
#085 Array Containing a Given Number
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Write a function to check if an array contains a particular number.
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/085 Array Containing a Given Number.js"Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.
This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.
//Write a function to check if an array contains a particular number.
function check(arr, el) {
return arr.includes(el);
}
import { assertEquals } from '../testHelper.js';
assertEquals(check([1, 2, 3, 4, 5], 3), true)
assertEquals(check([1, 1, 2, 1, 1], 3), false)
assertEquals(check([1, 1, 2, 1, 5, 4, 7], 7), true)
assertEquals(check([1, 1, 2, 1, 5, 4, 7], 8), false)
assertEquals(check([5, 5, 5, 6], 5), true)
assertEquals(check([], 5), false)