-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsevenBoom.js
More file actions
42 lines (35 loc) · 1.15 KB
/
sevenBoom.js
File metadata and controls
42 lines (35 loc) · 1.15 KB
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
39
40
41
42
/** Write a function that returns all the values from 1 to n inclusive, replacing all numbers that are a multiple of seven, or contain seven with "BOOM".
*
* @param {number} n - The number to count up to
* @returns {number[]} - An array matching the pattern described above
*
* ex: sevenBoom(20)
* returns: [1,2,3,4,5,6,'BOOM',8,9,10,11,12,13,'BOOM',15,16,'BOOM',18,19,20]
* Notice:
* 7 is replaced with 'BOOM' because it is a multiple of 7 (7 * 1 = 7) AND it contains a 7.
* 14 is replaced with 'BOOM' because it is a multiple of 7 (7 * 2 = 14)
* 17 is also replaced with 'BOOM' because it contains a 7.
*/
function sevenBoom(n) {
let boomArr = []
for(let i = 1; i <= n; i+= 1) {
if(i === 7 || i.toString().includes(7)||i % 7 === 0 ){
boomArr.push("BOOM")
} else {
boomArr.push(i)
}
}
return boomArr
// let boomArr = []
// for (let i = 0; i < 21; i++) {
// if (i % 7 === 0) {
// return 'BOOM'
// } else if (i % 14 === 0) {
// return 'BOOM'
// } else if (i % 17 === 0) {
// return 'BOOM'
// } else
// return i;
// }
}
module.exports = sevenBoom