-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuple.js
More file actions
32 lines (24 loc) · 796 Bytes
/
tuple.js
File metadata and controls
32 lines (24 loc) · 796 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
// Условие и примеры https://maxcode.dev/problems/tuple/
function Tuple(...items) {
if(new.target === undefined) {
return new Tuple(...items);
}
this.items = items;
}
Tuple.prototype.equals = function(otherInstance) {
if(
!(otherInstance instanceof Tuple) ||
otherInstance.items.length !== this.items.length ||
!otherInstance.items.every(item => this.items.includes(item))
) {
return false;
}
return true;
}
const colors1 = Tuple("red", "yellow", "green");
const colors2 = Tuple("red", "yellow", "green");
const colors3 = Tuple("red", "green", "blue");
console.log(colors1.equals(colors2)); // true
console.log(colors1.equals(colors3)); // false
console.log(colors1.equals("xxx")); // false
console.log(colors1 instanceof Tuple); // true