-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem6.js
39 lines (38 loc) · 982 Bytes
/
problem6.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
36
37
38
39
var utils = require('./lib/utils')();
var _ = require('underscore');
module.exports = function() {
var app = {
sumSquaresUpTo: utils.numFromSeq(
function(arry) {
return _.reduce(arry, function(cur, prev) { return cur + prev; }, 0);
},
function(n) {
var arry = [];
for(var i = 1; i <= n; i++) {
arry.push(Math.pow(i, 2));
}
return arry;
}
),
squareOfSumUpTo: function(n) {
var sumUpTo = utils.numFromSeq(
function(arry) {
return _.reduce(arry, function(cur, prev) { return cur + prev; }, 0);
},
function(n) {
var arry = [];
for(var i = 1; i <= n; i++) {
arry.push(i);
}
return arry;
}
);
var sum = sumUpTo(n);
return Math.pow(sum, 2);
},
sumSquaresDiff: function(n) {
return app.squareOfSumUpTo(n) - app.sumSquaresUpTo(n);
}
};
return app;
};