-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c34f1b4
commit fdec0ec
Showing
6 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}; |