Skip to content

Commit 83d5687

Browse files
committed
Migrated code for most exercises. A few remain to be ported and adapted.
1 parent 6e4ced6 commit 83d5687

File tree

79 files changed

+356
-198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+356
-198
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
.DS_Store
3+
npm-debug.log
4+
TODO.md
File renamed without changes.
File renamed without changes.

problems/basic_call/setup.js renamed to exercises/basic_call/exercise.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
"use strict"
22

3-
var input = require('../../input')
3+
var runner = require('../../runner')
4+
var util = require('util')
45

56
function randomInt(min, max) {
6-
return Math.floor((Math.random() * (max - min + 1)) + min)
7+
return Math.floor((Math.random() * (max - min)) + min)
78
}
89

9-
module.exports = input(new Array(randomInt(0, 20))
10-
.join(',')
11-
.split(',')
12-
.map(function() {
10+
var input = Array.apply(null, { length: randomInt(0, 20) }).map(function() {
1311
return randomInt(0, 10)
14-
})).wrap(function(input, mod) {
15-
var numbers = input[0]
12+
})
13+
14+
module.exports = runner.custom(function(fx, numbers) {
1615
var valid = 1
1716
var objects = [{quack: true}].concat(numbers.map(function(num) {
1817
switch(num) {
@@ -60,5 +59,5 @@ module.exports = input(new Array(randomInt(0, 20))
6059
}
6160
}))
6261

63-
console.log('Matched %d of %d valid objects from %d total.', mod.apply(mod, objects), valid, objects.length)
64-
})
62+
return util.format('Matched %d of %d valid objects from %d total.', fx.apply(null, objects), valid, objects.length)
63+
})(input)
File renamed without changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use strict"
2+
3+
var loremIpsum = require('lorem-ipsum')
4+
var runner = require('../../runner')
5+
6+
function randomInt(min, max) {
7+
return Math.floor((Math.random() * (max - min)) + min)
8+
}
9+
10+
function makeUser() {
11+
return {
12+
id: randomInt(0, 1000),
13+
name: loremIpsum().split(' ').slice(0, 2).map(function(word) {
14+
word[0] = word[0].toUpperCase();
15+
return word;
16+
}).join(' ')
17+
}
18+
}
19+
20+
function makeListOfUsers() {
21+
return Array.apply(null, { length : randomInt(10, 100) }).map(makeUser)
22+
}
23+
24+
var good = makeListOfUsers()
25+
var bad = makeListOfUsers()
26+
var lists = Array.apply(null, {length: 20}).map(function() {
27+
return Array.apply(null, {length: 20}).map(function() {
28+
if (Math.random() < 0.95) {
29+
return good[randomInt(0, 10)]
30+
} else {
31+
return bad[randomInt(0, 10)]
32+
}
33+
})
34+
})
35+
36+
module.exports = runner.custom(function(fx, good, lists) {
37+
var test = fx(good)
38+
39+
var goodLists = 0
40+
41+
lists.forEach(function(list) {
42+
test(list) && ++goodLists
43+
})
44+
45+
return 'found ' + goodLists + ' good lists!'
46+
}).hideInput(good, lists)

0 commit comments

Comments
 (0)