Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SimpleInterest #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
april-EXO wants to merge 4 commits into TheAlgorithms:master from april-EXO:master
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
* [ShorsAlgorithm](Maths/ShorsAlgorithm.js)
* [SieveOfEratosthenes](Maths/SieveOfEratosthenes.js)
* [SimpsonIntegration](Maths/SimpsonIntegration.js)
* [SimpleInterest](Maths/SimpleIntrest.js)
* [Softmax](Maths/Softmax.js)
* [SquareRoot](Maths/SquareRoot.js)
* [SumOfDigits](Maths/SumOfDigits.js)
Expand Down
15 changes: 15 additions & 0 deletions Maths/SimpleInterest.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @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} 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 = Math.floor((principal * interestRate * time) / 100)
return simpleInterest
}

export { SimpleInterest }
13 changes: 13 additions & 0 deletions Maths/test/SimpleInterest.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SimpleInterest } from '../SimpleInterest'

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)
})
})

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