Skip to content

Commit 511e5a0

Browse files
Format
1 parent 326bbdb commit 511e5a0

8 files changed

Lines changed: 211 additions & 175 deletions

File tree

concepts/type-checking/about.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
Knowning what type an object has is often very important for code to run smoothly and without errors.
44

55
Javascript has several ways to check the type of an object.
6-
~~~~exercism/note
6+
7+
```exercism/note
78
Javascript's type checking mechanisms are always soomewhat unreliable.
89
910
For true safety with types, you should probably use TypeScript, a language that builds on JavaScript, but with the type syntax of a static-typed language.
10-
~~~~
11+
```
12+
1113
## The `typeof` operator
1214

1315
The `typeof` operator returns the type of its input.
@@ -127,13 +129,13 @@ class Coffee {
127129
}
128130
const cappuccino = new Coffee();
129131

130-
Object.hasOwn(cappucino,'temperature');
132+
Object.hasOwn(cappucino, 'temperature');
131133
// => true
132134

133-
Object.hasOwn(cappucino,'constructor');
135+
Object.hasOwn(cappucino, 'constructor');
134136
// => false
135137

136-
Object.hasOwn(cappucino,'coolDown');
138+
Object.hasOwn(cappucino, 'coolDown');
137139
// => false
138140
```
139141

concepts/type-checking/introduction.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
Knowning what type an object has is often very important for code to run smoothly and without errors.
44

55
Javascript has several ways to check the type of an object.
6-
~~~~exercism/note
6+
7+
```exercism/note
78
Javascript's type checking mechanisms are always soomewhat unreliable.
89
910
For true safety with types, you should probably use TypeScript, a language that builds on JavaScript, but with the type syntax of a static-typed language.
10-
~~~~
11+
```
12+
1113
## The `typeof` operator
1214

1315
The `typeof` operator returns the type of its input.
@@ -127,13 +129,13 @@ class Coffee {
127129
}
128130
const cappuccino = new Coffee();
129131

130-
Object.hasOwn(cappucino,'temperature');
132+
Object.hasOwn(cappucino, 'temperature');
131133
// => true
132134

133-
Object.hasOwn(cappucino,'constructor');
135+
Object.hasOwn(cappucino, 'constructor');
134136
// => false
135137

136-
Object.hasOwn(cappucino,'coolDown');
138+
Object.hasOwn(cappucino, 'coolDown');
137139
// => false
138140
```
139141

exercises/concept/recycling-robot/.docs/hints.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Hints
22

3-
43
## 1. Check if a value is a boolean
54

65
- You can use `typeof` to find the type of a value.

exercises/concept/recycling-robot/.docs/instructions.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ You have been hired by a recycling center.
44
Due to lack of space, all the products are put on the same conveyor belt, but this has lead to different materials mixing together, making them unusable.
55
To fix this, you have been tasked with making functions to identify the type of a product.
66

7-
~~~~exercism/note
7+
```exercism/note
88
Many of the later tasks in this exercise can be solved using either `in` or `Object.hasOwn()`.
99
To practice, try to solve them with a mix of both.
10-
~~~~
10+
```
11+
1112
### 1. Check if a value is a boolean
1213

1314
Implement the `isBoolean` function, that checks if a value is a boolean.
1415

1516
```javascript
16-
isBoolean(true)
17+
isBoolean(true);
1718
// => true
1819

19-
isBoolean(null)
20+
isBoolean(null);
2021
// => false
2122
```
2223

@@ -28,16 +29,16 @@ Sometimes, the device for reading IDs bugs and reads a non-numeric value as `NaN
2829
Your function should be able to correctly handle this as well.
2930

3031
```javascript
31-
isNumber(42)
32+
isNumber(42);
3233
// => true
3334

34-
isNumber("Hello, World!")
35+
isNumber('Hello, World!');
3536
// => false
3637

37-
isNumber(42n)
38+
isNumber(42n);
3839
// => true
3940

40-
isNumber(NaN)
41+
isNumber(NaN);
4142
// => false
4243
```
4344

@@ -46,10 +47,10 @@ isNumber(NaN)
4647
Implement the `isObject` function, that should check if the value is actually an object, not null.
4748

4849
```javascript
49-
isObject({greeting:"Hello"})
50+
isObject({ greeting: 'Hello' });
5051
// => true
5152

52-
isObject(25n)
53+
isObject(25n);
5354
// => false
5455
```
5556

@@ -58,15 +59,14 @@ isObject(25n)
5859
Implement the `isNumericString` function, that should check if the value is a string but only consists of numbers.
5960

6061
```javascript
61-
isNumericString(42)
62+
isNumericString(42);
6263
// => false
6364

64-
isNumericString("42")
65+
isNumericString('42');
6566
// => true
6667

67-
isNumericString("Hi!")
68+
isNumericString('Hi!');
6869
// => false
69-
7070
```
7171

7272
### 5. Check if an object is electronic
@@ -80,10 +80,10 @@ class Duck {
8080
class WashingMachine extends ElectronicDevice {
8181
//...
8282
}
83-
isElectronic(new Duck())
83+
isElectronic(new Duck());
8484
// => false
8585

86-
isElectronic(new WashingMachine())
86+
isElectronic(new WashingMachine());
8787
// => false
8888
```
8989

@@ -92,21 +92,22 @@ isElectronic(new WashingMachine())
9292
Implement the `isNonEmptyArray` function, that checks if an object is a non empty array.
9393

9494
```javascript
95-
isNonEmptyArray([1,2,3])
95+
isNonEmptyArray([1, 2, 3]);
9696
// => true
9797

98-
isNonEmptyArray([])
98+
isNonEmptyArray([]);
9999
// => false
100100
```
101101

102102
### 7. Check if a value is an empty array
103103

104104
Implement the `isEmptyArray` function, that checks if an object is an empty array.
105+
105106
```javascript
106-
isEmptyArray([1,2,3])
107+
isEmptyArray([1, 2, 3]);
107108
// => false
108109

109-
isEmptyArray([])
110+
isEmptyArray([]);
110111
// => true
111112
```
112113

@@ -117,10 +118,10 @@ Implement the `assertHasId` function, that will throw an `Error` if an object is
117118
If an object does have the `id` property, it should not return anything.
118119

119120
```javascript
120-
assertHasId({id:42,color:"red"})
121+
assertHasId({ id: 42, color: 'red' });
121122
// => undefined
122123

123-
assertHasId({color:"green"})
124+
assertHasId({ color: 'green' });
124125
// Error: "Object is missing the 'id' property"
125126
```
126127

@@ -151,33 +152,34 @@ Implement the `hasIdProperty` function, that checks whether an object has an `id
151152
```javascript
152153
class MyClass {
153154
constructor() {
154-
this.number = "42"
155-
this.id = "BC269327FE1D9B95"
155+
this.number = '42';
156+
this.id = 'BC269327FE1D9B95';
156157
}
157158
}
158159
class MyNewClass {
159160
constructor() {
160-
this.number = "42"
161-
this._id = "BC269327FE1D9B95"
161+
this.number = '42';
162+
this._id = 'BC269327FE1D9B95';
162163
}
163-
get id(){
164-
return this._id
164+
get id() {
165+
return this._id;
165166
}
166167
}
167-
hasIdProperty(new MyClass())
168+
hasIdProperty(new MyClass());
168169
// => true
169170

170-
hasIdProperty(new MyNewClass())
171+
hasIdProperty(new MyNewClass());
171172
// => false
172173
```
174+
173175
### 11. Check if an object has a defined `type` property
174176

175177
Implement the `hasDefinedType` function, that checks if an object has a `type` property that is not `undefined`.
176178

177179
```javascript
178-
hasDefinedType({type:undefined,color:"red"})
180+
hasDefinedType({ type: undefined, color: 'red' });
179181
// => false
180182

181-
hasDefinedType({type:"car",color:"green"})
183+
hasDefinedType({ type: 'car', color: 'green' });
182184
// => true
183185
```

exercises/concept/recycling-robot/.docs/introduction.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
Knowning what type an object has is often very important for code to run smoothly and without errors.
44

55
Javascript has several ways to check the type of an object.
6-
~~~~exercism/note
6+
7+
```exercism/note
78
Javascript's type checking mechanisms are always soomewhat unreliable.
89
910
For true safety with types, you should probably use TypeScript, a language that builds on JavaScript, but with the type syntax of a static-typed language.
10-
~~~~
11+
```
12+
1113
## The `typeof` operator
1214

1315
The `typeof` operator returns the type of its input.
@@ -127,13 +129,13 @@ class Coffee {
127129
}
128130
const cappuccino = new Coffee();
129131

130-
Object.hasOwn(cappucino,'temperature');
132+
Object.hasOwn(cappucino, 'temperature');
131133
// => true
132134

133-
Object.hasOwn(cappucino,'constructor');
135+
Object.hasOwn(cappucino, 'constructor');
134136
// => false
135137

136-
Object.hasOwn(cappucino,'coolDown');
138+
Object.hasOwn(cappucino, 'coolDown');
137139
// => false
138140
```
139141

0 commit comments

Comments
 (0)