From e17e0d0afdfb66b2d382706aaff586a919592e0e Mon Sep 17 00:00:00 2001 From: ChickenHawkXP <47929127+ChickenHawkXP@users.noreply.github.com> Date: Sat, 30 Oct 2021 22:10:23 -0400 Subject: [PATCH 1/5] Added FindMax to Maths --- Maths/FindMax.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Maths/FindMax.js diff --git a/Maths/FindMax.js b/Maths/FindMax.js new file mode 100644 index 0000000000..d154224680 --- /dev/null +++ b/Maths/FindMax.js @@ -0,0 +1,20 @@ +/** + * Function to find the maximum number given an array of integers + * Returns the maximum number of the array + * If the array is empty it returns the string 'Array is empty' + */ + +export const findMax = (arr) => { + if (arr.length === 0) + return 'Array is empty' + + let max = arr[0] + arr.forEach(element =>{ + if (element > max){ + max = element + } + }) + return max +} + +export { findMax } \ No newline at end of file From 79a2b16f0d0ae8fda139ff46316f834f93b623f1 Mon Sep 17 00:00:00 2001 From: ChickenHawkXP <47929127+ChickenHawkXP@users.noreply.github.com> Date: Sat, 30 Oct 2021 22:10:23 -0400 Subject: [PATCH 2/5] Added FindMax to Maths --- Maths/FindMax.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Maths/FindMax.js diff --git a/Maths/FindMax.js b/Maths/FindMax.js new file mode 100644 index 0000000000..e5efc2e857 --- /dev/null +++ b/Maths/FindMax.js @@ -0,0 +1,18 @@ +/** + * Function to find the maximum number given an array of integers + * Returns the maximum number of the array + * If the array is empty it returns the string 'Array is empty' + */ + +export const findMax = (arr) => { + if (arr.length === 0) + return 'Array is empty' + + let max = arr[0] + arr.forEach(element =>{ + if (element > max){ + max = element + } + }) + return max +} \ No newline at end of file From 58bd7f42ef0de0a986ccd8d2a16c48626266f6d0 Mon Sep 17 00:00:00 2001 From: ChickenHawkXP <47929127+ChickenHawkXP@users.noreply.github.com> Date: Sat, 30 Oct 2021 22:10:23 -0400 Subject: [PATCH 3/5] Added FindMax to Maths Added FindMax test --- Maths/FindMax.js | 18 ++++++++++++++++++ Maths/test/FindMax.test.js | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Maths/FindMax.js create mode 100644 Maths/test/FindMax.test.js diff --git a/Maths/FindMax.js b/Maths/FindMax.js new file mode 100644 index 0000000000..e5efc2e857 --- /dev/null +++ b/Maths/FindMax.js @@ -0,0 +1,18 @@ +/** + * Function to find the maximum number given an array of integers + * Returns the maximum number of the array + * If the array is empty it returns the string 'Array is empty' + */ + +export const findMax = (arr) => { + if (arr.length === 0) + return 'Array is empty' + + let max = arr[0] + arr.forEach(element =>{ + if (element > max){ + max = element + } + }) + return max +} \ No newline at end of file diff --git a/Maths/test/FindMax.test.js b/Maths/test/FindMax.test.js new file mode 100644 index 0000000000..e626ff064b --- /dev/null +++ b/Maths/test/FindMax.test.js @@ -0,0 +1,17 @@ +import { findMax } from '../FindMax' + +test('Should return the highest number in the array', () => { + const max = findMax([2,5,1,12,43,1,9]) + expect(max).toBe(43) + }) + +test('Should return the highest number in the array', () => { + const max = findMax([21,513,6]) + expect(max).toBe(513) + }) + +test('Should return the highest number in the array', () => { + const max = findMax([]) + expect(max).toBe('Array is empty') + }) + \ No newline at end of file From fa2186b53926f826ae19004d23ce9d0499e128c9 Mon Sep 17 00:00:00 2001 From: ChickenHawkXP <47929127+ChickenHawkXP@users.noreply.github.com> Date: Sun, 31 Oct 2021 15:21:53 -0400 Subject: [PATCH 4/5] Fix --- Maths/FindMax.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Maths/FindMax.js b/Maths/FindMax.js index 6b2be11ff2..b108d9e3bc 100644 --- a/Maths/FindMax.js +++ b/Maths/FindMax.js @@ -15,8 +15,4 @@ export const findMax = (arr) => { } }) return max -<<<<<<< HEAD -} -======= -} ->>>>>>> 7ae8d92c904e3991a3c19779d50fb8f936bbe3a7 + } \ No newline at end of file From af752e95d29f0a10ecd71007db38add0757d21f2 Mon Sep 17 00:00:00 2001 From: ChickenHawkXP <47929127+ChickenHawkXP@users.noreply.github.com> Date: Mon, 1 Nov 2021 17:29:58 -0400 Subject: [PATCH 5/5] Styling errors --- Maths/FindMax.js | 19 +++++++++---------- Maths/test/FindMax.test.js | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Maths/FindMax.js b/Maths/FindMax.js index b108d9e3bc..5ff30d7d0a 100644 --- a/Maths/FindMax.js +++ b/Maths/FindMax.js @@ -5,14 +5,13 @@ */ export const findMax = (arr) => { - if (arr.length === 0) - return 'Array is empty' + if (arr.length === 0) { return 'Array is empty' } - let max = arr[0] - arr.forEach(element =>{ - if (element > max){ - max = element - } - }) - return max - } \ No newline at end of file + let max = arr[0] + arr.forEach(element => { + if (element > max) { + max = element + } + }) + return max +} diff --git a/Maths/test/FindMax.test.js b/Maths/test/FindMax.test.js index e626ff064b..6c39d3dbc2 100644 --- a/Maths/test/FindMax.test.js +++ b/Maths/test/FindMax.test.js @@ -1,17 +1,16 @@ import { findMax } from '../FindMax' test('Should return the highest number in the array', () => { - const max = findMax([2,5,1,12,43,1,9]) - expect(max).toBe(43) - }) + const max = findMax([2, 5, 1, 12, 43, 1, 9]) + expect(max).toBe(43) +}) test('Should return the highest number in the array', () => { - const max = findMax([21,513,6]) - expect(max).toBe(513) - }) + const max = findMax([21, 513, 6]) + expect(max).toBe(513) +}) test('Should return the highest number in the array', () => { - const max = findMax([]) - expect(max).toBe('Array is empty') - }) - \ No newline at end of file + const max = findMax([]) + expect(max).toBe('Array is empty') +})