forked from timoxley/functional-javascript-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
64 lines (60 loc) · 1.45 KB
/
Copy pathsetup.js
File metadata and controls
64 lines (60 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict"
var input = require('../../input')
function randomInt(min, max) {
return Math.floor((Math.random() * (max - min + 1)) + min)
}
module.exports = input(new Array(randomInt(0, 20))
.join(',')
.split(',')
.map(function() {
return randomInt(0, 10)
})).wrap(function(input, mod) {
var numbers = input[0]
var valid = 1
var objects = [{quack: true}].concat(numbers.map(function(num) {
switch(num) {
case 0:
valid++
return {quack: true}
break;
case 1:
valid++
return {quack: false}
case 2:
valid++
var obj = Object.create(null)
obj.quack = true
return obj
case 3:
valid++
var obj = Object.create(null)
obj.quack = undefined
return obj
case 3:
var proto = { quack: true }
return Object.create(proto)
case 4:
var proto = Object.create(null)
proto.quack = true
return Object.create(proto)
case 5:
valid++
var proto = Object.create(null)
proto.quack = true
var obj = Object.create(proto)
obj.quack = undefined
return obj
case 6:
valid++
return {
quack: true,
hasOwnProperty: function() {
return false
}
}
default:
return {}
}
}))
console.log('Matched %d of %d valid objects from %d total.', mod.apply(mod, objects), valid, objects.length)
})