In the game Set, three cards form a set if each of the cards are identical or completely different for each of the four properties. All three cards must:
The four properties are:
Here, a set is represented by an array containing three cards. Each card is represented by an object of properties and values. Write a function that determines whether three cards constitute a valid set.
Here is an example of a set:
[
{ color: "red", number: 1, shade: "empty", shape: "squiggle" },
{ color: "red", number: 2, shade: "lined", shape: "diamond" },
{ color: "red", number: 3, shade: "full", shape: "oval" }
]
// "Same" properties: color
// "Different" properties: numbers, shading and shapes
The following is not a set:
[
{ color: "red", number: 1, shade: "empty", shape: "squiggle" },
{ color: "red", number: 2, shade: "lined", shape: "diamond" },
{ color: "purple", number: 3, shade: "full", shape: "oval" }
]
// Colors are not all identical, but not all different.
isSet([
{ color: "green", number: 1, shade: "empty", shape: "squiggle" },
{ color: "green", number: 2, shade: "empty", shape: "diamond" },
{ color: "green", number: 3, shade: "empty", shape: "oval" }
]) ➞ true
isSet([
{ color: "purple", number: 1, shade: "full", shape: "oval" },
{ color: "green", number: 1, shade: "full", shape: "oval" },
{ color: "red", number: 1, shade: "full", shape: "oval" }
]) ➞ true
isSet([
{ color: "purple", number: 3, shade: "full", shape: "oval" },
{ color: "green", number: 1, shade: "full", shape: "oval" },
{ color: "red", number: 3, shade: "full", shape: "oval" }
]) ➞ false