From a32c2b630f9f49a32984bc6d06744cfbde5d7076 Mon Sep 17 00:00:00 2001 From: april Date: Sun, 7 Aug 2022 23:35:44 +0800 Subject: [PATCH 1/4] SimpleIntrest [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/from-referrer/) [know more](https://www.gitpod.io/docs/pull-requests/) ### Describe your change: - [ x] Add an algorithm? - [ ] Fix a bug or typo in an existing algorithm? - [ ] Documentation change? ### Checklist: - [ x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Javascript/blob/master/CONTRIBUTING.md). - [ x] This pull request is all my own work -- I have not plagiarized. - [ x] I know that pull requests will not be merged if they fail the automated tests. - [ x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. - [ x] All new JavaScript files are placed inside an existing directory. - [ x] All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames. **Example:**`UserProfile.js` is allowed but `userprofile.js`,`Userprofile.js`,`user-Profile.js`,`userProfile.js` are not - [ x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. - [ x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`. --- DIRECTORY.md | 1 + Maths/SimpleIntrest.js | 15 +++++++++++++++ Maths/test/SimpleIntrest.test.js | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 Maths/SimpleIntrest.js create mode 100644 Maths/test/SimpleIntrest.test.js diff --git a/DIRECTORY.md b/DIRECTORY.md index dccfbb7c9a..e22c78b2d0 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -198,6 +198,7 @@ * [ShorsAlgorithm](Maths/ShorsAlgorithm.js) * [SieveOfEratosthenes](Maths/SieveOfEratosthenes.js) * [SimpsonIntegration](Maths/SimpsonIntegration.js) + * [SimpleIntrest](Maths/SimpleIntrest.js) * [Softmax](Maths/Softmax.js) * [SquareRoot](Maths/SquareRoot.js) * [SumOfDigits](Maths/SumOfDigits.js) diff --git a/Maths/SimpleIntrest.js b/Maths/SimpleIntrest.js new file mode 100644 index 0000000000..5f16fd918f --- /dev/null +++ b/Maths/SimpleIntrest.js @@ -0,0 +1,15 @@ +/** + * @function SimpleIntrest + * @description to calculate the amount of interest charged on a sum at a given rate and for a given period of time + * @param {number} principal - input: the principal amount + * @param {number} intrestRate - input: the rate of interest in percentage + * @param {number} time - input: the time period in year + * @return {number} simpleIntrest + */ + +const SimpleIntrest = (principal, intrestRate, time) => { + const simpleIntrest = parseInt((principal * intrestRate * time) / 100) + return simpleIntrest +} + +export { SimpleIntrest } diff --git a/Maths/test/SimpleIntrest.test.js b/Maths/test/SimpleIntrest.test.js new file mode 100644 index 0000000000..b0212b3e6d --- /dev/null +++ b/Maths/test/SimpleIntrest.test.js @@ -0,0 +1,13 @@ +import { SimpleIntrest } from '../SimpleIntrest' + +describe('Testing Simple Intrest Rate calculate function', () => { + it('should 750 for principal = 5000, rate = 5%, time = 3 yrs', () => { + expect(SimpleIntrest(5000, 5, 3)).toBe(750) + }) + it('should 750 for principal = 1000, rate = 3%, time = 2 yrs', () => { + expect(SimpleIntrest(10000, 3, 2)).toBe(600) + }) + it('should 750 for principal = 40000, rate = 0.1%, time = 10 yrs', () => { + expect(SimpleIntrest(40000, 0.1, 10)).toBe(400) + }) +}) From 1d3ef4d1a4b8de000432706f38d2b26882044ff4 Mon Sep 17 00:00:00 2001 From: april Date: Sun, 7 Aug 2022 23:42:09 +0800 Subject: [PATCH 2/4] fix --- DIRECTORY.md | 2 +- Maths/{SimpleIntrest.js => SimpleInterest.js} | 12 ++++++------ Maths/test/SimpleInterest.test.js | 13 +++++++++++++ Maths/test/SimpleIntrest.test.js | 13 ------------- 4 files changed, 20 insertions(+), 20 deletions(-) rename Maths/{SimpleIntrest.js => SimpleInterest.js} (56%) create mode 100644 Maths/test/SimpleInterest.test.js delete mode 100644 Maths/test/SimpleIntrest.test.js diff --git a/DIRECTORY.md b/DIRECTORY.md index e22c78b2d0..8cd38b0042 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -198,7 +198,7 @@ * [ShorsAlgorithm](Maths/ShorsAlgorithm.js) * [SieveOfEratosthenes](Maths/SieveOfEratosthenes.js) * [SimpsonIntegration](Maths/SimpsonIntegration.js) - * [SimpleIntrest](Maths/SimpleIntrest.js) + * [SimpleInterest](Maths/SimpleIntrest.js) * [Softmax](Maths/Softmax.js) * [SquareRoot](Maths/SquareRoot.js) * [SumOfDigits](Maths/SumOfDigits.js) diff --git a/Maths/SimpleIntrest.js b/Maths/SimpleInterest.js similarity index 56% rename from Maths/SimpleIntrest.js rename to Maths/SimpleInterest.js index 5f16fd918f..4f5c0295ed 100644 --- a/Maths/SimpleIntrest.js +++ b/Maths/SimpleInterest.js @@ -1,15 +1,15 @@ /** - * @function SimpleIntrest + * @function SimpleInterest * @description to calculate the amount of interest charged on a sum at a given rate and for a given period of time * @param {number} principal - input: the principal amount * @param {number} intrestRate - input: the rate of interest in percentage * @param {number} time - input: the time period in year - * @return {number} simpleIntrest + * @return {number} simpleInterest */ -const SimpleIntrest = (principal, intrestRate, time) => { - const simpleIntrest = parseInt((principal * intrestRate * time) / 100) - return simpleIntrest +const SimpleInterest = (principal, interestRate, time) => { + const simpleInterest = parseInt((principal * interestRate * time) / 100) + return simpleInterest } -export { SimpleIntrest } +export { SimpleInterest } diff --git a/Maths/test/SimpleInterest.test.js b/Maths/test/SimpleInterest.test.js new file mode 100644 index 0000000000..588b6840a4 --- /dev/null +++ b/Maths/test/SimpleInterest.test.js @@ -0,0 +1,13 @@ +import { SimpleInterest } from '../SimpleIntrest' + +describe('Testing Simple Interest Rate calculate function', () => { + it('should 750 for principal = 5000, rate = 5%, time = 3 yrs', () => { + expect(SimpleInterest(5000, 5, 3)).toBe(750) + }) + it('should 750 for principal = 1000, rate = 3%, time = 2 yrs', () => { + expect(SimpleInterest(10000, 3, 2)).toBe(600) + }) + it('should 750 for principal = 40000, rate = 0.1%, time = 10 yrs', () => { + expect(SimpleInterest(40000, 0.1, 10)).toBe(400) + }) +}) diff --git a/Maths/test/SimpleIntrest.test.js b/Maths/test/SimpleIntrest.test.js deleted file mode 100644 index b0212b3e6d..0000000000 --- a/Maths/test/SimpleIntrest.test.js +++ /dev/null @@ -1,13 +0,0 @@ -import { SimpleIntrest } from '../SimpleIntrest' - -describe('Testing Simple Intrest Rate calculate function', () => { - it('should 750 for principal = 5000, rate = 5%, time = 3 yrs', () => { - expect(SimpleIntrest(5000, 5, 3)).toBe(750) - }) - it('should 750 for principal = 1000, rate = 3%, time = 2 yrs', () => { - expect(SimpleIntrest(10000, 3, 2)).toBe(600) - }) - it('should 750 for principal = 40000, rate = 0.1%, time = 10 yrs', () => { - expect(SimpleIntrest(40000, 0.1, 10)).toBe(400) - }) -}) From 45a4ec119fade88c2e570eb987ccd1eced738d3c Mon Sep 17 00:00:00 2001 From: april Date: Sun, 7 Aug 2022 23:45:23 +0800 Subject: [PATCH 3/4] fix --- Maths/test/SimpleInterest.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/test/SimpleInterest.test.js b/Maths/test/SimpleInterest.test.js index 588b6840a4..054b740746 100644 --- a/Maths/test/SimpleInterest.test.js +++ b/Maths/test/SimpleInterest.test.js @@ -1,4 +1,4 @@ -import { SimpleInterest } from '../SimpleIntrest' +import { SimpleInterest } from '../SimpleInterest' describe('Testing Simple Interest Rate calculate function', () => { it('should 750 for principal = 5000, rate = 5%, time = 3 yrs', () => { From d809becfe2905793736f6f40fbfd5beecae25c59 Mon Sep 17 00:00:00 2001 From: april Date: Mon, 8 Aug 2022 04:11:40 +0800 Subject: [PATCH 4/4] fix --- Maths/SimpleInterest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Maths/SimpleInterest.js b/Maths/SimpleInterest.js index 4f5c0295ed..fbc7622785 100644 --- a/Maths/SimpleInterest.js +++ b/Maths/SimpleInterest.js @@ -2,13 +2,13 @@ * @function SimpleInterest * @description to calculate the amount of interest charged on a sum at a given rate and for a given period of time * @param {number} principal - input: the principal amount - * @param {number} intrestRate - input: the rate of interest in percentage + * @param {number} interestRate - input: the rate of interest in percentage * @param {number} time - input: the time period in year * @return {number} simpleInterest */ const SimpleInterest = (principal, interestRate, time) => { - const simpleInterest = parseInt((principal * interestRate * time) / 100) + const simpleInterest = Math.floor((principal * interestRate * time) / 100) return simpleInterest }

AltStyle によって変換されたページ (->オリジナル) /