const _ = require('../lib/underScore.js')
const Utils = function() {}
Utils.existy = function(x) {
return x != null
}
Utils.truthy = function(x) {
return (x != false) && this.existy(x)
}
function cat(head, ...rest) {
if(Utils.existy(head)) {
return head.concat.apply(head, rest)
}
}
let a = cat([1,2,3], [4,5], [6,7,8])
console.log(a)
function constructor(head, ...tail) {
return cat([head], ...tail)
}
let b = constructor(11, [1,2,3])
console.log(b)
function mapCat(func, coll) {
return cat.apply(null, coll.map(func))
}
function butLast(coll) {
return Array.from(coll).slice(0, -1)
}
function interPose(inter, coll) {
return butLast(mapCat(function(e) {
return constructor(e, [inter])
}, coll))
}
let d = interPose(',', [11,1,2,3])
console.log(d)
- 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