Skip to content

Commit

Permalink
Add helper functionallity
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-acc committed Feb 10, 2023
1 parent c34f1b4 commit fdec0ec
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
8 changes: 8 additions & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface NumbersResponse {
avg: number;
sum: number;
max: number;
min: number;
}
export declare const numbersInformation: (numbers: number[]) => NumbersResponse | null;
export {};
40 changes: 39 additions & 1 deletion build/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
"use strict";
console.log('Hello Andres');
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.numbersInformation = void 0;
var numbersInformation = function (numbers) {
if (numbers.length === 0) {
return null;
}
return {
avg: numbers.reduce(function (a, b) { return a + b; }) / numbers.length,
sum: numbers.reduce(function (a, b) { return a + b; }),
max: Math.max.apply(Math, __spreadArray([], __read(numbers), false)),
min: Math.min.apply(Math, __spreadArray([], __read(numbers), false))
};
};
exports.numbersInformation = numbersInformation;
1 change: 1 addition & 0 deletions build/index.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
14 changes: 14 additions & 0 deletions build/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
test('should return correct operations', function () {
expect((0, _1.numbersInformation)([1, 2, 3])).toEqual({
avg: 2,
sum: 6,
max: 3,
min: 1
});
});
test('should return null on empty array', function () {
expect((0, _1.numbersInformation)([])).toBe(null);
});
14 changes: 14 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { numbersInformation } from '.';

test('should return correct operations', () => {
expect(numbersInformation([1,2,3])).toEqual({
avg: 2,
sum: 6,
max: 3,
min: 1
})
});

test('should return null on empty array', () => {
expect(numbersInformation([])).toBe(null);
});
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
console.log('Hello Andres');
interface NumbersResponse {
avg: number;
sum: number;
max: number;
min: number;
}

export const numbersInformation = (numbers: number[]): NumbersResponse | null => {
if(numbers.length === 0) {
return null;
}
return {
avg: numbers.reduce((a,b) => a+b) / numbers.length,
sum: numbers.reduce((a,b) => a+b),
max: Math.max(...numbers),
min: Math.min(...numbers)
}
};

0 comments on commit fdec0ec

Please sign in to comment.