-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsevenBoom.js
More file actions
35 lines (29 loc) · 980 Bytes
/
sevenBoom.js
File metadata and controls
35 lines (29 loc) · 980 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
/** 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 newArr = []
for (let i = 1; i <= n; i++) {
if (i % 7 === 0) {
newArr.push("BOOM")
}
else if (i.toString().includes(7)) {
newArr.push("BOOM")
}
else {
newArr.push(i)
}
}
return newArr
}
console.log(sevenBoom(59))
module.exports = sevenBoom