CodeWars: Defuse The Bombs Solution

1console.log(Object.keys(Bomb))
2
3// 10
4console.log(Bomb.diffuse.toString())
5Bomb.diffuse(Bomb.key)
6
7// 9
8console.log(Bomb.hint)
9console.log(Bomb.diffuse.toString())
10while (Bomb.hint === "just keep trying") {
11 Bomb.diffuse(Bomb.key)
12}
13console.log("\n\n")
14
15// 8
16console.log(Bomb.hint)
17console.log(Bomb.diffuse.toString())
18Bomb.diffuse(this.BombKey)
19console.log("\n\n")
20
21// 7
22console.log(Bomb.hint)
23console.log(Bomb.diffuse.toString())
24function diffuseTheBomb() {
25 return true
26}
27Bomb.diffuse()
28console.log("\n\n")
29
30// 6
31console.log(Bomb.hint)
32console.log(Bomb.diffuse.toString())
33console.log(
34 Buffer.from("VGhlIGtleSBpcyAiMy4xNDE1OSI=", "base64").toString("utf-8")
35)
36Bomb.diffuse(3.14159)
37console.log("\n\n")
38
39// 5
40console.log(Bomb.hint)
41console.log(Bomb.diffuse.toString())
42const date = new Date()
43date.setFullYear(date.getFullYear() - 4)
44Bomb.diffuse(date)
45console.log("\n\n")
46
47// 4
48console.log(Bomb.hint)
49console.log(Bomb.diffuse.toString())
50Bomb.diffuse(Object.freeze({ key: 43 }))
51console.log("\n\n")
52
53// 3
54console.log(Bomb.hint)
55console.log(Bomb.diffuse.toString())
56Bomb.diffuse({
57 applied: false,
58 valueOf: function () {
59 let val = !this.applied ? 9 : 11
60 this.applied = true
61 return val
62 },
63})
64console.log("\n\n")
65
66// 2
67console.log(Bomb.hint)
68console.log(Bomb.diffuse.toString())
69const MathRandom = Math.random
70Math.random = function () {
71 return {
72 valueOf: () => {
73 let val = !this.applied ? 0.5 : 1
74 this.applied = true
75 return val
76 },
77 }
78}
79Bomb.diffuse(42)
80Math.random = MathRandom
81console.log("\n\n")
82
83// 1
84console.log(Bomb.hint)
85console.log(Bomb.diffuse.toString())
86Array.prototype.valueOf = function () {
87 return this.reduce((acc, el) => acc + el, 0)
88}
89Bomb.diffuse(Buffer.from("yes", "ascii").toString("base64"))
90console.log("\n\n")

Comments

Loading comments...

Tags

codewars

Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.

Next Post

LeetCode: Convert Bst To Greater Tree

Feb 10, 2021

HoningJS

Search Posts