Description
Given a array of integer, find and return its maximum number.
Constraints
Rules
- Do not use prehensive javascript function like Number.max
export function maxNumber(arr: number[]): number {
let max = 0;
for (let item of arr) {
if (item > max) { max = item; }
}
return max;
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { maxNumber } from "./solution";
// TODO Add your tests here
describe("example", function() {
it("Find max number", function() {
assert.strictEqual(maxNumber([3,2,1,5]), 5);
assert.strictEqual(maxNumber([3,2,1,5,9]), 9);
assert.strictEqual(maxNumber([3,2,-1,6]), 6);
assert.strictEqual(maxNumber([-3,2,10,1,5]), 10);
});
});