from functools import reduce def find_max(arr): return reduce(lambda a, b: a if a > b else b, arr)
- from functools import reduce
- def find_max(arr):
max = 0for i in range(len(arr)):if arr[i] > max:max = arr[i]return max- return reduce(lambda a, b: a if a > b else b, arr)
# TODO: Replace examples and use TDD by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(actual, expected, [optional] message) # test.assert_not_equals(actual, expected, [optional] message) # You can use Test.describe and Test.it to write BDD style test groupings test.assert_equals(find_max([1, 2, 3, 4, 5]), 5) test.assert_equals(find_max([1, 2, 17, 4, 5]), 17) test.assert_equals(find_max([-6, 1, 2, 3, 4, 5, 2]), 5)
- # TODO: Replace examples and use TDD by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(actual, expected, [optional] message)
- # test.assert_not_equals(actual, expected, [optional] message)
- # You can use Test.describe and Test.it to write BDD style test groupings
test.assert_equals(find_max([1, 2, 3, 4, 5]), 5)- test.assert_equals(find_max([1, 2, 3, 4, 5]), 5)
- test.assert_equals(find_max([1, 2, 17, 4, 5]), 17)
- test.assert_equals(find_max([-6, 1, 2, 3, 4, 5, 2]), 5)
const chai = require("chai"); const assert = chai.assert; describe("Find max number in array", function() { it("finds the max number in array",function() { assert.strictEqual(findMax([1, 2, 3, 4, 5]), 5) assert.strictEqual(findMax([1, 2, 3, -4, 5]), 5) assert.strictEqual(findMax([-1, -2, -3, -4, -5]), -1) }) })
Test.assertEquals(findMax([1, 2, 3, 4, 5]), 5)Test.assertEquals(findMax([1, 2, 3, -4, 5]), 5)Test.assertEquals(findMax([-1, -2, -3, -4, -5]), -1)- const chai = require("chai");
- const assert = chai.assert;
- describe("Find max number in array", function() {
- it("finds the max number in array",function() {
- assert.strictEqual(findMax([1, 2, 3, 4, 5]), 5)
- assert.strictEqual(findMax([1, 2, 3, -4, 5]), 5)
- assert.strictEqual(findMax([-1, -2, -3, -4, -5]), -1)
- })
- })