You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: problems/async_loops/problem.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
This code is broken!
2
2
3
-
A Java developer has committed this terrible code to our codebase
4
-
and didn't test it!
3
+
A Java developer has committed this terrible code to our codebase and didn't test it!
5
4
6
5
```js
7
6
functionloadUsers(userIds, load, done) {
@@ -15,14 +14,14 @@ function loadUsers(userIds, load, done) {
15
14
module.exports= loadUsers
16
15
```
17
16
18
-
# Task: Fix this code! The callback should be called with all the users loaded.
19
-
The order of the users should match the order of supplied user ids.
20
-
Because this function is asynchronous, we do not care about its return value.
17
+
# Task
18
+
19
+
Fix this code! The callback should be called with all the users loaded.
20
+
The order of the users should match the order of supplied user ids. Because this function is asynchronous, we do not care about its return value.
21
21
22
22
## Arguments
23
23
* userIds: an Array of numeric user ids.
24
-
* load: a Function used to load user objects. Expects a numeric id and a callback. The callback will be called with the
25
-
result of loading the user with the specified id (either a user object or null).
24
+
* load: a Function used to load user objects. Expects a numeric id and a callback. The callback will be called with the result of loading the user with the specified id (either a user object or null).
26
25
* done: a Function that expects an Array of user objects (as retrieved from `load`).
Copy file name to clipboardExpand all lines: problems/basic_call/problem.md
+8-22Lines changed: 8 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,10 @@
1
-
JavaScript implements 'duck' typing. Duck typing is a style of dynamic typing in
2
-
which an object's methods and properties determine the valid semantics,
3
-
rather than its inheritance from a particular class or implementation of a
4
-
specific interface. The name of the concept refers to the duck test, attributed
5
-
to James Whitcomb Riley, which may be phrased as follows:
1
+
JavaScript implements 'duck' typing. Duck typing is a style of dynamic typing in which an object's methods and properties determine the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface. The name of the concept refers to the duck test, attributed to James Whitcomb Riley, which may be phrased as follows:
6
2
7
3
"When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck"
8
4
9
-
In JavaScript, in order to write robust programs we sometimes need to
10
-
check an object conforms to the type that we need.
5
+
In JavaScript, in order to write robust programs we sometimes need to check an object conforms to the type that we need.
11
6
12
-
We can use Object#hasOwnProperty to detect if an object 'has' a property defined on itself (i.e. not
13
-
inherited from its prototype):
7
+
We can use Object#hasOwnProperty to detect if an object 'has' a property defined on itself (i.e. not inherited from its prototype):
We didn't give the duck a .hasOwnProperty method, where did it come from?
26
20
27
-
Duck was created with the `{}` syntax, and as such
28
-
it inherits from Object.prototype:
21
+
Duck was created with the `{}` syntax, and as such it inherits from Object.prototype:
29
22
30
23
```js
31
24
var object = {quack:true}
@@ -50,10 +43,7 @@ object.hasOwnProperty('quack')
50
43
// => TypeError: Object object has no method 'hasOwnProperty'
51
44
```
52
45
53
-
We can still use `hasOwnProperty` from the `Object.prototype` though,
54
-
if we call it with the `this` value set to something that 'looks like
55
-
an object'. Function#call allows us to invoke any function with
56
-
an altered `this` value.
46
+
We can still use `hasOwnProperty` from the `Object.prototype` though, if we call it with the `this` value set to something that 'looks like an object'. Function#call allows us to invoke any function with an altered `this` value.
57
47
58
48
```js
59
49
// the first argument to call becomes the value of `this`
Write a function `duckCount` that returns the number of arguments passed to it which
68
-
have a property 'quack' defined directly on them. Do not match values inherited
69
-
from prototypes.
57
+
Write a function `duckCount` that returns the number of arguments passed to it which have a property 'quack' defined directly on them. Do not match values inherited from prototypes.
70
58
71
59
Example:
72
60
@@ -77,8 +65,7 @@ duckCount(duck, notDuck) // 1
77
65
```
78
66
## Arguments
79
67
80
-
* You will be passed 0-20 arguments. Each argument could be of any type with any
81
-
properties. Some of these items will have a 'quack' property.
68
+
* You will be passed 0-20 arguments. Each argument could be of any type with any properties. Some of these items will have a 'quack' property.
82
69
83
70
## Conditions
84
71
@@ -88,8 +75,7 @@ duckCount(duck, notDuck) // 1
88
75
89
76
## Hint
90
77
91
-
* The arguments variable, available in every function,
92
-
is an object that quacks like an Array:
78
+
* The `arguments` variable, available in every function, is an *Object* that quacks like an *Array*:
Copy file name to clipboardExpand all lines: problems/basic_every_some/problem.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
# Task
2
2
3
-
Return a function that takes a list of valid users, and returns a function that returns true
4
-
if all of the supplied users exist in the original list of users.
3
+
Return a function that takes a list of valid users, and returns a function that returns true if all of the supplied users exist in the original list of users.
5
4
6
5
You only need to check that the ids match.
7
6
@@ -35,8 +34,7 @@ testAllValid([
35
34
36
35
* goodUsers: a list of valid users
37
36
38
-
Use array#some and Array#every to check every user passed to your returned
39
-
function exists in the array passed to the exported function.
37
+
Use array#some and Array#every to check every user passed to your returned function exists in the array passed to the exported function.
Copy file name to clipboardExpand all lines: problems/basic_recursion/problem.md
+6-16Lines changed: 6 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,6 @@
1
-
Recursion is a fundamental programming concept which can lead to elegant and efficient solutions to
2
-
algorithmic problems. In fact, recursion is so powerful, all iterating behaviour can be defined using
3
-
recursive functions. You will find recursion indispensable when iterating over nested data structures.
1
+
Recursion is a fundamental programming concept which can lead to elegant and efficient solutions to algorithmic problems. In fact, recursion is so powerful, all iterating behaviour can be defined using recursive functions. You will find recursion indispensable when iterating over nested data structures.
4
2
5
-
A recursive function is a function which calls itself. For example, this recursive function will
6
-
take an array of words, and return an array of those words, uppercased.
3
+
A recursive function is a function which calls itself. For example, this recursive function will take an array of words, and return an array of those words, uppercased.
7
4
8
5
```js
9
6
functiontoUpperArray(items) {
@@ -17,27 +14,20 @@ function toUpperArray(items) {
The point of this exercise is to familiarise yourself with recursion by implementing a familiar
21
-
interface using a recursive function.
17
+
The point of this exercise is to familiarise yourself with recursion by implementing a familiar interface using a recursive function.
22
18
23
19
# Task
24
20
25
21
Implement Array#reduce using recursion.
26
22
27
-
To test your reduction works correctly we will use your reduce implementation to execute our solution
28
-
to the previous basic_reduce problem. i.e. your reduce function will be passed an array of words, and
29
-
a function, and an initial value which will return an object containing the counts for each word found
30
-
in the array. You don't need to implement this functionality, it will be supplied to your reduce
31
-
implementation.
23
+
To test your reduction works correctly we will use your reduce implementation to execute our solution to the previous basic_reduce problem. i.e. your reduce function will be passed an array of words, and a function, and an initial value which will return an object containing the counts for each word found in the array. You don't need to implement this functionality, it will be supplied to your reduce implementation.
32
24
33
-
For simplicity, your implementation of reduce **need not replicate the behaviour of a reduce missing an
34
-
initial value**. You may assume the initial value will always be supplied.
25
+
For simplicity, your implementation of reduce **need not replicate the behaviour of a reduce missing an initial value**. You may assume the initial value will always be supplied.
35
26
36
27
## Arguments
37
28
38
29
* arr: An Array to reduce over
39
-
* fn: Function to use as the reduction step.
40
-
Like regular Array#reduce, this function must be passed previousValue, currentValue, index and the array we're iterating over.
30
+
* fn: Function to use as the reduction step. Like regular Array#reduce, this function must be passed previousValue, currentValue, index and the array we're iterating over.
41
31
* init: Initial value of the reduction. Unlike Array#reduce, this value is required (and you may assume it will always be supplied).
Copy file name to clipboardExpand all lines: problems/basic_reduce/problem.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,6 @@
1
1
# Task
2
2
3
-
Given an Array of strings, use `Array#reduce` to create an object that
4
-
contains the number of times each string occured in the array. Return the
5
-
object directly (no need to console.log).
3
+
Given an Array of strings, use `Array#reduce` to create an object that contains the number of times each string occured in the array. Return the object directly (no need to console.log).
Copy file name to clipboardExpand all lines: problems/blocking_event_loop/problem.md
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,8 @@
1
1
# Task
2
2
3
-
Modify the recursive `repeat` function provided in the boilerplate,
4
-
such that it does not block the event loop (i.e. Timers and IO handlers can fire).
5
-
This necessarily requires repeat to be asynchronous.
3
+
Modify the recursive `repeat` function provided in the boilerplate, such that it does not block the event loop (i.e. Timers and IO handlers can fire). This necessarily requires repeat to be asynchronous.
6
4
7
-
A timeout is queued to fire after 1 second, which will print the results
8
-
of the test and exit the process. `repeat` should release control of the event
9
-
loop such that the timeout fires before 1500 milliseconds elapse.
5
+
A timeout is queued to fire after 1 second, which will print the results of the test and exit the process. `repeat` should release control of the event loop such that the timeout fires before 1500 milliseconds elapse.
10
6
11
7
Try to perform as many operations as you can before the timeout fires!
0 commit comments