-
Notifications
You must be signed in to change notification settings - Fork 0
/
yourPlayground.js
212 lines (163 loc) Β· 4.23 KB
/
yourPlayground.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Array slice
// const fruitss = ["π", "π", "π", "π«"]
// console.log(fruitss.slice(0,2))
const introducer = (name, shirt) => {
const person = {
name: name,
shirt: shirt,
assets: 100000,
liabilities: 50000,
netWorth: function() {
return this.assets - this.liabilities
}
}
const intro = `Hi, my name is ${person.name} and the color of my shirt is ${person.shirt} and my net worth is $${person.netWorth()} USD`
return intro
}
// console.log(introducer("Chinmay Sonawne", "Black"))
// const fruits = ["π", "π", "π", "π«"]
// for (const fruit of fruits) {
// console.log(fruit)
// }
// const numbers = [1,2,3,4,5,6]
// let temp = 0
// for (const number of numbers) {
// temp += number
// }
// console.log(temp)
// const max = (numbers) => {
// const count = {}
// for (const number of numbers) {
// if (number in count) {
// count[number]++
// } else {
// count[number] = 1
// }
// }
// return count
// }
// console.log(max([1,2,3,4,4,4,5,5,6,6,7,8,9]))
const wordcount = (sentence) => {
const count = {}
for (const number of sentence.split(" ")) {
if (number in count) {
count[number]++
} else {
count[number] = 1
}
}
return count
}
// console.log(wordcount("Hello World Hello Hello Hello World There"))
function sum(numbers) {
return numbers.reduce((prev, nex) => {
return prev + nex
})
}
// console.log(sum([1,2,3,4]))
fruits = ["π", "π", "π", "π«"]
// console.log(fruits[Math.floor(Math.random() * fruits.length)])
// setTimeout(() => {
// console.log("Hello World")
// }, 3000);
class Car {
constructor (name, color, topSpeed) {
// properties
this.name = name
this.color = color
this.topSpeed = topSpeed
this.currentSpeed = 0
}
getCurrentSpeed () {
return this.currentSpeed
}
zeroToSizty () {
console.log("WOOO That was fast as fcuk boi")
this.currentSpeed = 60
console.log(this.currentSpeed)
}
// default values
drive (speed = 10) {
// console.log("just drove 2 miles")
this.currentSpeed += speed
console.log(`Driving at ${this.currentSpeed} mph`)
}
brake () {
// console.log("Brake applied")
this.currentSpeed -= 10
console.log(`Speed after braking : ${this.currentSpeed}`)
}
stop () {
this.currentSpeed = 0
console.log(`Speed after stop method : ${this.currentSpeed}`)
}
}
const ferrari = new Car("ferrari", "red", 250)
const porsche = new Car("porsche", "yellow", 260)
// console.log(porsche)
// console.log(porsche.getCurrentSpeed())
// porsche.drive()
// porsche.drive()
// porsche.drive()
// porsche.drive()
// const nums = [1,2,3,4,5].forEach(_ => porsche.drive())
// porsche.brake()
// porsche.zeroToSizty()
// porsche.stop()
// console.log(ferrari)
// console.log("Current Speed : " + ferrari.currentSpeed)
// ferrari.drive()
// ferrari.brake()
// console.log("Current Speed : " + ferrari.currentSpeed)
// ferrari.drive()
// console.log("Current Speed : " + ferrari.currentSpeed)
// ferrari.drive()
// console.log("Current Speed : " + ferrari.currentSpeed)
// ferrari.drive()
// ferrari.zeroToSizty()
// ferrari.drive()
// ferrari.drive()
// ferrari.drive()
// ferrari.drive()
// ferrari.drive()
// ferrari.brake()
// ferrari.brake()
// ferrari.stop()
// console.log(ferrari.currentSpeed)
Array.prototype.myPush = function (item) {
this[this.length] = item
return this
}
const fruits_2 = ["π", "π", "π", "π«"]
fruits_2.myPush("π₯")
fruits_2.myPush("π")
fruits_2.myPush("πͺ")
// console.log(fruits_2)
class Bank {
constructor (money) {
this.money = money
}
balance () {
console.log("Your Balance : $"+this.money)
}
withdraw (value = 0) {
if (value > this.money) {
console.log("Insufficient Balace dude")
return
}
this.money -= value
console.log(`Your new balance after withdrawing : $${this.money}`)
}
deposit (value = 0) {
this.money += value
console.log(`Your new balance after deposit : $${this.money}`)
}
}
// chinmay = new Bank(100)
// chinmay.balance()
// chinmay.withdraw(50)
// chinmay.deposit(100)
// chinmay.deposit(500)
// chinmay.balance()
// chinmay.withdraw(50)
// chinmay.withdraw(1000)