-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayFront9.js
More file actions
executable file
·38 lines (30 loc) · 835 Bytes
/
arrayFront9.js
File metadata and controls
executable file
·38 lines (30 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
morning warmup coding exercise
@mistergenest
*/
const arrayFront9 =(nums)=>{
let stop = nums.length < 4 ? nums.length : 3;
let flag = false;
for (let i=0; i <= stop ; i++){
if (nums[i] !== 9){
continue;
}
flag = true;
}
return flag;
}
// TESTS:
console.log(arrayFront9([1, 2, 9, 3, 4])); // true
console.log(arrayFront9([1, 2, 3, 4, 9])); // false
console.log(arrayFront9([1, 2, 3, 4, 5])); // false
console.log(arrayFront9([9])); // true
console.log(arrayFront9([ 9, 9])); // true
console.log(arrayFront9([1])); // false
console.log(arrayFront9([])); // false
/*
Given an array of ints, return true if one of the first 4 elements in
the array is a 9. The array length may be less than 4.
arrayFront9([1, 2, 9, 3, 4]) → true
arrayFront9([1, 2, 3, 4, 9]) → false
arrayFront9([1, 2, 3, 4, 5]) → false
*/