-
Notifications
You must be signed in to change notification settings - Fork 3
/
in-op.rn
62 lines (50 loc) · 1.09 KB
/
in-op.rn
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
# with Array
var arr = [1,2,3,4,5]
# with if-else
if 1 in arr {
print("Data found.")
} else {
print("Not found.")
}
# Normal testing
print(2 in arr)
# with while loop
while 3 in arr {
print(arr_pop(arr))
}
# this should also work for HashMap as well.
arr = [1,2,3,4,5]
assert 4 in arr
const hm = {
"key1": "value1",
"key2": "value2"
}
assert "key2" in hm # This will search in HashMap->Keys
class Person {
fun __constructor__(name) {
this.name = name
this.friends = []
}
fun befriend(other) {
arr_append(this.friends, other)
arr_append(other.friends, this)
}
fun dump() {
print("Person(name=\"" + this.name + "\", friends=" + this.friends + ")")
}
fun __contains__(friend_name) {
for friend in this.friends {
if friend.name == friend_name {
return true
}
}
return false
}
}
const john = Person("John")
const bob = Person("Bob")
const alice = Person("Alice")
john.befriend(bob)
assert "Bob" in john
assert "John" in bob
assert not "Alice" in john