Skip to content
Merged
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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ npm install math-problems
import { area, toCelsius, isEven, populationDensity, population } from 'math-problems';

// Calculate the area of a circle with radius 5
console.log(area.circle(5)); // { area: 78 }
console.log(area.circle(5)); // 78

// Convert 100°F to Celsius
console.log(toCelsius(100)); // 37
Expand All @@ -36,23 +36,23 @@ All area functions return an object with a floored `area` value.

- **Rectangle**
`rect(base: number, height: number)`
`area.rect(4, 5) ➔ { area: 20 }`
`area.rect(4, 5) ➔ 20`

- **Triangle**
`triangle(base: number, height: number)`
`area.triangle(4, 5) ➔ { area: 10 }`
`area.triangle(4, 5) ➔ 10`

- **Rhombus**
`rhombus(D: number, d: number)`
`area.rhombus(8, 6) ➔ { area: 24 }`
`area.rhombus(8, 6) ➔ 24`

- **Trapezoid**
`trapezoid(B: number, b: number, height: number)`
`area.trapezoid(10, 6, 5) ➔ { area: 40 }`
`area.trapezoid(10, 6, 5) ➔ 40`

- **Circle**
`circle(radius: number)`
`area.circle(3) ➔ { area: 28 }`
`area.circle(3) ➔ 28`

### 🌡️ Temperature Conversions
Convert between Celsius (°C), Fahrenheit (°F), and Kelvin (K).
Expand Down Expand Up @@ -124,4 +124,4 @@ Contributions are welcome! Please follow the [contribution guidelines](https://g

## License
MIT © Igor Figueiredo
[Full License Text](LICENSE)
[Full License Text](LICENSE)
35 changes: 10 additions & 25 deletions src/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,26 @@ export const area = {
*
* base * height
*/
rect: (base: number, height: number): AreaResult => {
return {
area: Math.floor(base * height),
};
rect: (base: number, height: number): number => {
return Math.floor(base * height);
},
/**
* @param base Size of the base of the triangle
* @param height The height of the triangle
*
* (base * height) / 2
*/
triangle: (base: number, height: number): AreaResult => {
return {
area: Math.floor((base * height) / 2),
};
triangle: (base: number, height: number): number => {
return Math.floor((base * height) / 2);
},
/**
* @param D larger diagonal
* @param d smaller diagonal
*
* (D * d) / 2
*/
rhombus: (D: number, d: number): AreaResult => {
return {
area: Math.floor((D * d) / 2),
};
rhombus: (D: number, d: number): number => {
return Math.floor((D * d) / 2);
},
/**
* @param B Larger base
Expand All @@ -44,24 +38,15 @@ export const area = {
*
* ((B + b) * height) / 2
*/
trapezoid: (B: number, b: number, height: number): AreaResult => {
return {
area: Math.floor(((B + b) * height) / 2),
};
trapezoid: (B: number, b: number, height: number): number => {
return Math.floor(((B + b) * height) / 2);
},
/**
* @param radius Circle radius
*
* π * (radius * radius)
*/
circle: (radius: number): AreaResult => {
return {
area: Math.floor(PI * (radius * radius)),
};
circle: (radius: number): number => {
return Math.floor(PI * (radius * radius));
},
};

export type AreaResult = {
area?: number;
perimeter?: number;
};
Loading