-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem8.js
35 lines (33 loc) · 881 Bytes
/
problem8.js
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
var _ = require('underscore');
var utils = require('./lib/utils')();
module.exports = function() {
function prdConsecutive(n) {
return function(numStr) {
var productsArray = [];
var numArray = numStr.split('');
var products = function(prev, cur) { return prev*cur; };
for(var i = 0; i <= numStr.length-n; i++) {
var end = i + n;
var nums = numArray.slice(i, end);
var product = _.reduce(nums, products, 1);
productsArray.push(product);
}
return productsArray;
};
}
return {
productsConsecutive2: prdConsecutive(2),
biggestProductCons2: utils.numFromSeq(
function(array) {
return _.max(array);
},
prdConsecutive(2)
),
biggestProductCons5: utils.numFromSeq(
function(array) {
return _.max(array);
},
prdConsecutive(5)
)
};
};