-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathCircular Objects #1 - Running around in circles.js
24 lines (18 loc) · 1.81 KB
/
Circular Objects #1 - Running around in circles.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
/*
Description:
Circular Objects #1 - Running around in circles
Overview
A circular object is any object containing a property that refers to itself. An example of a circular object can be found right here at Codewars - the very programming environment that they provide you with. Just try it - print the details of the current programming environment to the console (I will not be giving you any hints - you'll have to figure this out yourself) and scroll through the printed text until you find a property named global. As you would expect, the printed output would say that it is [circular]. Now let's try printing the global property of the programming envoronment to the console. What do you see? If you followed the instructions properly you would see the exact same thing being printed out! Impressed? You can test this further by then printing the global property of the global property of the current environment to the console and you would still see the exact same thing being printed. In fact, no matter how many levels you go "inside" the object, you would still see the exact same thing being printed out.
Which leads us to the task described below ...
Task
Define a circular object circular such that the following are true:
circular.value === "Hello World"
circular === circular.self
circular.self === circular.self.self
... and so on.
NOTE: The code above is pseudocode. If you actually tested your circular object like this with equality or identity operators, it would not work as object literals do not have an intrinsic value.
Articles of Interest
Unfortunately, in this Kata, any article I recommend to you would immediately give away the solution so I have decided to not recommend any articles in this Kata of the series. I apologise for any inconvenience caused.
*/
let circular ={value:"Hello World"}
circular.self = circular