Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function result() {
- function binary(a, b, operation) {
- const array = [];
- for (let index = 0; index <= 1; index++) {
- const result = operation(a[index], b[index]);
- array.push(result);
- }
- return array;
- }
- function product(a, b) {
- return a * b;
- }
- function reduceBinary(a, b) {
- }
- function add(a, b) {
- return binary(a, b, (a, b) => a + b);
- }
- function multiply(a, b) {
- return binary(a, [b, b], product);
- }
- function length(a) {
- return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2));
- }
- function dot(a, b) {
- return binary(a, b, product).reduce((prev, curr) => prev + curr, 0);
- }
- function cross(a, b) {
- return a[0] * b[1] - a[1] * b[0];
- }
- return {
- 'add': add,
- 'multiply': multiply,
- 'length': length,
- 'dot': dot,
- 'cross': cross,
- };
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement