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