Skip to content

Commit 8829f26

Browse files
committed
Merge pull request timoxley#47 from Sequoia/master
Normalize export style in problem.md
2 parents 92c5cbf + bf751c6 commit 8829f26

File tree

16 files changed

+204
-370
lines changed

16 files changed

+204
-370
lines changed

problems/async_loops/problem.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ A Java developer has committed this terrible code to our codebase
44
and didn't test it!
55

66
```js
7-
87
function loadUsers(userIds, load, done) {
98
var users = []
109
for (var i = 0; i < userIds.length; i++) {
@@ -14,38 +13,29 @@ function loadUsers(userIds, load, done) {
1413
}
1514

1615
module.exports = loadUsers
17-
1816
```
1917

20-
Task: Fix this code! The callback should be called with all the users loaded.
21-
18+
# Task: Fix this code! The callback should be called with all the users loaded.
2219
The order of the users should match the order of supplied user ids.
2320
Because this function is asynchronous, we do not care about its return value.
2421

25-
Arguments:
26-
22+
## Arguments
2723
* userIds: an Array of numeric user ids.
2824
* load: a Function used to load user objects. Expects a numeric id and a callback. The callback will be called with the
2925
result of loading the user with the specified id (either a user object or null).
3026
* done: a Function that expects an Array of user objects (as retrieved from `load`).
3127

32-
Conditions:
33-
28+
## Conditions
3429
* Do not use any for/while loops.
3530
* The order of the results in `done` must be the same as they were specified in `userIds`.
3631
* Users should be loaded in parallel i.e. the entire job should not take more than 1 second.
3732

38-
Hint:
33+
## Hint
3934

4035
* You don't need to use a sort to maintain ordering.
4136

42-
43-
#################
44-
## Boilerplate ##
45-
#################
46-
37+
## Boilerplate
4738
```js
48-
4939
function loadUsers(userIds, load, done) {
5040
var users = []
5141
for (var i = 0; i < userIds.length; i++) {
@@ -55,5 +45,4 @@ function loadUsers(userIds, load, done) {
5545
}
5646

5747
module.exports = loadUsers
58-
5948
```

problems/basic_call/problem.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ We can use Object#hasOwnProperty to detect if an object 'has' a property defined
1313
inherited from its prototype):
1414

1515
```js
16-
1716
var duck = {
1817
quack: function() {
1918
console.log('quack')
2019
}
2120
}
2221

2322
duck.hasOwnProperty('quack') // => true
24-
2523
```
2624

2725
We didn't give the duck a .hasOwnProperty method, where did it come from?
@@ -30,18 +28,15 @@ Duck was created with the `{}` syntax, and as such
3028
it inherits from Object.prototype:
3129

3230
```js
33-
3431
var object = {quack: true}
3532

3633
Object.getPrototypeOf(object) === Object.prototype // => true
3734
object.hasOwnProperty('quack') // => true
38-
3935
```
4036

4137
But what if an object doesn't inherit from Object.prototype?
4238

4339
```js
44-
4540
// create an object with 'null' prototype.
4641
var object = Object.create(null)
4742
object.quack = function() {
@@ -53,7 +48,6 @@ Object.getPrototypeOf(object) === null // => true
5348

5449
object.hasOwnProperty('quack')
5550
// => TypeError: Object object has no method 'hasOwnProperty'
56-
5751
```
5852

5953
We can still use `hasOwnProperty` from the `Object.prototype` though,
@@ -62,15 +56,13 @@ an object'. Function#call allows us to invoke any function with
6256
an altered `this` value.
6357

6458
```js
65-
6659
// the first argument to call becomes the value of `this`
6760
// the rest of the arguments are passed to the function as per
6861

6962
Object.prototype.hasOwnProperty.call(object, 'quack') // => true
70-
7163
```
7264

73-
Task:
65+
# Task:
7466

7567
Write a function `duckCount` that returns the number of arguments passed to it which
7668
have a property 'quack' defined directly on them. Do not match values inherited
@@ -79,40 +71,36 @@ from prototypes.
7971
Example:
8072

8173
```js
82-
8374
var notDuck = Object.create({quack: true})
8475
var duck = {quack: true}
8576
duckCount(duck, notDuck) // 1
86-
8777
```
88-
Arguments:
78+
## Arguments
8979

9080
* You will be passed 0-20 arguments. Each argument could be of any type with any
9181
properties. Some of these items will have a 'quack' property.
9282

93-
Conditions:
83+
## Conditions
9484

9585
* Do not use any for/while loops.
9686
* Do not create any counter/accumulator variables.
9787
* You do not need to define any additional name functions
9888
unless a stub is provided in the boilerplate.
9989

100-
Hint:
90+
## Hint
10191

10292
* The arguments variable, available in every function,
10393
is an object that quacks like an Array:
10494

10595
```js
106-
10796
{
10897
0: 'argument0',
10998
1: 'argument1', // etc
11099
length: 2
111100
}
112-
113101
```
114102

115-
Resources:
103+
## Resources
116104

117105
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
118106
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
@@ -121,16 +109,12 @@ Resources:
121109
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments
122110

123111

124-
#################
125-
## Boilerplate ##
126-
#################
112+
## Boilerplate
127113

128114
```js
129-
130115
function duckCount() {
131116
// SOLUTION GOES HERE
132117
}
133118

134119
module.exports = duckCount
135-
136120
```

problems/basic_every_some/problem.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
Task:
1+
# Task
22

33
Return a function that takes a list of valid users, and returns a function that returns true
44
if all of the supplied users exist in the original list of users.
55

66
You only need to check that the ids match.
77

8-
#############
9-
## Example ##
10-
#############
8+
## Example
119

1210
```js
13-
1411
var goodUsers = [
1512
{ id: 1 },
1613
{ id: 2 },
@@ -32,31 +29,28 @@ testAllValid([
3229
{ id: 1 }
3330
])
3431
// => false
35-
3632
```
3733

38-
Arguments:
34+
## Arguments
3935

4036
* goodUsers: a list of valid users
4137

4238
Use array#some and Array#every to check every user passed to your returned
4339
function exists in the array passed to the exported function.
4440

45-
Resources:
41+
## Resources
4642

4743
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/every
4844
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some
4945

50-
#################
51-
## Boilerplate ##
52-
#################
46+
## Boilerplate
5347

5448
```js
55-
56-
module.exports = function checkUsersValid(goodUsers) {
49+
function checkUsersValid(goodUsers) {
5750
return function(submittedUsers) {
5851
// SOLUTION GOES HERE
5952
};
6053
}
6154

55+
module.exports = checkUsersValid
6256
```

problems/basic_filter/problem.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
1+
# Task
12
Use Array#filter to write a function called `getShortMessages`.
23

34
`getShortMessages` takes an array of objects with '.message' properties
45
and returns an array of messages that are *less than < 50 characters long*.
56

6-
Arguments:
7+
## Arguments
78

89
* messages: an Array of 10 to 100 random objects that look something like this:
910

1011
```js
11-
1212
{
1313
message: 'Esse id amet quis eu esse aute officia ipsum.' // random
1414
}
15-
1615
```
1716

18-
Conditions:
17+
## Conditions
1918

2019
* Do not use for loops or Array#forEach.
2120

22-
Hint: Try chaining some Array methods!
21+
## Hint
2322

24-
Expected Output:
23+
* Try chaining some Array methods!
24+
25+
## Expected Output
2526

2627
The function should return an array containing the messages themselves,
2728
*without their containing object*.
2829

2930
e.g.
30-
3131
```
32-
3332
[ 'Tempor quis esse consequat sunt ea eiusmod.',
3433
'Id culpa ad proident ad nulla laborum incididunt.',
3534
'Ullamco in ea et ad anim anim ullamco est.',
3635
'Est ut irure irure nisi.' ]
37-
3836
```
3937

40-
Resources:
38+
## Resources
4139

4240
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
4341
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
4442

45-
#################
46-
## Boilerplate ##
47-
#################
43+
## Boilerplate
4844

4945
```js
50-
51-
module.exports = function getShortMessages(messages) {
46+
function getShortMessages(messages) {
5247
// SOLUTION GOES HERE
5348
}
5449

50+
module.exports = getShortMessages
5551
```
Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
##########
2-
## Task ##
3-
##########
1+
# Task
42

53
Create a new "BetterUser" type that extends "User" by overriding
64
the User's `.toString` method.
@@ -9,7 +7,6 @@ Your exported function will be passed the constructor function
97
for a "User" type that looks like this:
108

119
```js
12-
1310
/**
1411
* User Constructor.
1512
*
@@ -39,33 +36,36 @@ User.prototype.displayName = function() {
3936
User.prototype.toString = function() {
4037
return '[User:'+this.displayName()+']'
4138
}
42-
4339
```
4440

4541
Note: you do not need to copy this into your solution.
4642

47-
#####################
48-
## Expected Output ##
49-
#####################
43+
## Expected Output
5044

5145
From your exported function, return a `BetterUser` constructor function
5246
that extends `User` with a custom `toString` method that works like so:
5347

5448
```js
55-
5649
var joe = new BetterUser('Mr.', 'Joe Smith') // pass in title and name
5750
console.log('Hello ' + joe) // 'Hello [BetterUser: Mr. Joe Smith]'
58-
5951
```
6052

61-
#################
62-
## Boilerplate ##
63-
#################
53+
## Conditions
6454

65-
```js
55+
* Don't call the User constructor unnecessarily!
56+
* Don't use `__proto__`
57+
58+
## Resources
59+
60+
* http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/
61+
* http://tobyho.com/2011/11/11/js-object-inheritance/
62+
* http://hughfdjackson.com/javascript/2012/01/05/prototypes:-the-short%28est-possible%29-story/
6663

64+
## Boilerplate
65+
66+
```js
6767
// User is a constructor
68-
module.exports = function(User) {
68+
function upgradeUser(User) {
6969

7070
// EDIT THESE AS NECESSARY
7171
function BetterUser() {
@@ -75,19 +75,5 @@ module.exports = function(User) {
7575
return BetterUser
7676
}
7777

78+
module.exports = upgradeUser
7879
```
79-
80-
################
81-
## Conditions ##
82-
################
83-
84-
* Don't call the User constructor unnecessarily!
85-
* Don't use `__proto__`
86-
87-
###############
88-
## Resources ##
89-
###############
90-
91-
* http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/
92-
* http://tobyho.com/2011/11/11/js-object-inheritance/
93-
* http://hughfdjackson.com/javascript/2012/01/05/prototypes:-the-short%28est-possible%29-story/

0 commit comments

Comments
 (0)