Skip to content

Commit

Permalink
Merge pull request #91 from 201flaviosilva-labs/90-move-math-function…
Browse files Browse the repository at this point in the history
…s-to-a-folder

refactor: move Maths function to Maths folder #90
  • Loading branch information
201flaviosilva committed Oct 17, 2022
2 parents 09253ae + 63d1751 commit c982f09
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/average.js → src/Maths/average.js
Expand Up @@ -12,6 +12,9 @@ import { sum } from "./sum.js";
*
* @param {...number} numbers - the numbers to average
* @returns {number}
*
* @function average
* @memberof Maths
*/
export function average(...numbers) {
if (!numbers.length) return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/clamp.js → src/Maths/clamp.js
Expand Up @@ -14,5 +14,8 @@
* @param {number} [min=0] - Minimum value
* @param {number} [max=1] - Maximum value
* @returns {number} The fixed value
*
* @function clamp
* @memberof Maths
*/
export function clamp(value, min = 0, max = 1) { return Math.min(max, Math.max(min, value)); }
3 changes: 3 additions & 0 deletions src/degreesToRadians.js → src/Maths/degreesToRadians.js
Expand Up @@ -7,5 +7,8 @@
*
* @param {number} d - the degrees value to convert in radians
* @returns {number} converted the given degrees in radian
*
* @function degreesToRadians
* @memberof Maths
*/
export function degreesToRadians(d) { return d * (Math.PI / 180); }
3 changes: 3 additions & 0 deletions src/divideEvenly.js → src/Maths/divideEvenly.js
Expand Up @@ -9,6 +9,9 @@
* @param {number} [max=10] The maximum value to return.
* @param {number} [numberDivisions=5] The number of divisions to use.
* @returns {number[]} An array of evenly spaced numbers.
*
* @function divideEvenly
* @memberof Maths
*/
export function divideEvenly(min = 0, max = 10, numberDivisions = 5) {
const result = [];
Expand Down
3 changes: 3 additions & 0 deletions src/division.js → src/Maths/division.js
Expand Up @@ -9,6 +9,9 @@
*
* @param {...number} numbers - the numbers to division
* @returns {number}
*
* @function division
* @memberof Maths
*/
export function division(...numbers) {
if (!numbers.length) return 0;
Expand Down
File renamed without changes.
Expand Up @@ -16,6 +16,9 @@
* @param {number} [origin.x=0] - x axis value
* @param {number} [origin.y=0] - y axis value
* @returns {Point} position {x:number,y:number} the x and y position
*
* @function getPositionWithAngleDistance
* @memberof Maths
*/
export function getPositionWithAngleDistance(angle, distance, origin = { x: 0, y: 0 }) {
return {
Expand Down
48 changes: 48 additions & 0 deletions src/Maths/index.js
@@ -0,0 +1,48 @@
import { average } from "./average.js";
import { clamp } from "./clamp.js";
import { degreesToRadians } from "./degreesToRadians.js";
import { divideEvenly } from "./divideEvenly.js";
import { division } from "./division.js";
import { getPositionWithAngleDistance } from "./getPositionWithAngleDistance.js";
import { isEven, isOdd } from "./isEvenOdd.js";
import { invertedLerp } from "./invertedLerp.js";
import { isMultipleOf } from "./isMultipleOf.js";
import { isNarcissisticNumber } from "./isNarcissisticNumber.js";
import { lerp } from "./lerp.js";
import { makeNegative } from "./makeNegative.js";
import { map } from "./map.js";
import { median } from "./median.js";
import { mode } from "./mode.js";
import { multiplication } from "./multiplication.js";
import { radiansToDegrees } from "./radiansToDegrees.js";
import { range } from "./range.js";
import { subtraction } from "./subtraction.js";
import { sum } from "./sum.js";

/**
* Math functions
*
* @namespace Maths
*/
export {
average,
clamp,
degreesToRadians,
divideEvenly,
division,
getPositionWithAngleDistance,
invertedLerp,
isEven, isOdd,
isMultipleOf,
isNarcissisticNumber,
lerp,
makeNegative,
map,
median,
mode,
multiplication,
radiansToDegrees,
range,
subtraction,
sum,
};
3 changes: 3 additions & 0 deletions src/invertedLerp.js → src/Maths/invertedLerp.js
Expand Up @@ -15,5 +15,8 @@ import { clamp } from "./clamp.js";
* @param {number} start - The start of the range.
* @param {number} end - The end of the range.
* @returns {number} value between 0 and 1, representing where the "value" parameter falls within the range defined by start and end
*
* @function invertedLerp
* @memberof Maths
*/
export function invertedLerp(value, start, end) { return clamp((value - start) / (end - start)); }
6 changes: 6 additions & 0 deletions src/isEvenOdd.js → src/Maths/isEvenOdd.js
Expand Up @@ -7,6 +7,9 @@
*
* @param {number} number - The number to check
* @returns {boolean}
*
* @function isEven
* @memberof Maths
*/
export function isEven(number) { return number % 2 == 0 }

Expand All @@ -19,5 +22,8 @@ export function isEven(number) { return number % 2 == 0 }
*
* @param {number} number - The number to check
* @returns {boolean}
*
* @function isOdd
* @memberof Maths
*/
export function isOdd(number) { return number % 2 == 1 }
3 changes: 3 additions & 0 deletions src/isMultipleOf.js → src/Maths/isMultipleOf.js
Expand Up @@ -15,5 +15,8 @@
* @param {number} dividend - the number check is multiple
* @param {number} divisor - divisor number
* @returns {boolean}
*
* @function isMultipleOf
* @memberof Maths
*/
export function isMultipleOf(dividend, divisor) { return dividend % divisor == 0 }
Expand Up @@ -20,6 +20,9 @@
*
* @param {number} n - number to check if a narcissistic
* @returns {boolean}
*
* @function isNarcissisticNumber
* @memberof Maths
*/
export function isNarcissisticNumber(n) {
const stringN = String(n);
Expand Down
3 changes: 3 additions & 0 deletions src/lerp.js → src/Maths/lerp.js
Expand Up @@ -11,5 +11,8 @@
* @param {number} max - Maximum value
* @returns {number} The result of the function
* @see {@link https://en.wikipedia.org/wiki/Linear_interpolation}
*
* @function lerp
* @memberof Maths
*/
export function lerp(value, min, max) { return min + (max - min) * value; }
3 changes: 3 additions & 0 deletions src/makeNegative.js → src/Maths/makeNegative.js
Expand Up @@ -8,5 +8,8 @@
*
* @param {number} number - The number you want to convert
* @returns {number} - a negative number
*
* @function makeNegative
* @memberof Maths
*/
export function makeNegative(number) { return Math.abs(number) * -1; };
3 changes: 3 additions & 0 deletions src/map.js → src/Maths/map.js
Expand Up @@ -17,5 +17,8 @@
* @param {number} start2 - Start of the range 2
* @param {number} end2 - End of the range 2
* @returns {number} the value un the range
*
* @function map
* @memberof Maths
*/
export function map(value, start1, end1, start2, end2) { return (value - start1) * (end2 - start2) / (end1 - start1) + start2; }
5 changes: 4 additions & 1 deletion src/median.js → src/Maths/median.js
@@ -1,5 +1,5 @@
import { isEven } from "./isEvenOdd";
import { arraySortAscending } from "./arraySortAscending";
import { arraySortAscending } from "../arraySortAscending";

/**
* Returns the median of the givens numbers
Expand All @@ -12,6 +12,9 @@ import { arraySortAscending } from "./arraySortAscending";
*
* @param {...number} numbers - the numbers to get the median
* @returns {number}
*
* @function median
* @memberof Maths
*/
export function median(...numbers) {
const { length } = numbers;
Expand Down
3 changes: 3 additions & 0 deletions src/mode.js → src/Maths/mode.js
Expand Up @@ -5,6 +5,9 @@
*
* @param {...number} numbers - the numbers to get the median
* @returns {number}
*
* @function mode
* @memberof Maths
*/
export function mode(...numbers) {
const mode = {};
Expand Down
3 changes: 3 additions & 0 deletions src/multiplication.js → src/Maths/multiplication.js
Expand Up @@ -8,6 +8,9 @@
*
* @param {...number} numbers - the numbers to multiplication
* @returns {number}
*
* @function multiplication
* @memberof Maths
*/
export function multiplication(...numbers) {
return numbers.reduce((acc, curr) => acc * curr, 1);
Expand Down
3 changes: 3 additions & 0 deletions src/radiansToDegrees.js → src/Maths/radiansToDegrees.js
Expand Up @@ -7,5 +7,8 @@
*
* @param {number} r - radians value to convert in degrees
* @returns {number} converted the given radian in degrees
*
* @function radiansToDegrees
* @memberof Maths
*/
export function radiansToDegrees(r) { return r * (180 / Math.PI); }
3 changes: 3 additions & 0 deletions src/range.js → src/Maths/range.js
Expand Up @@ -13,6 +13,9 @@
* @param {number} [step=1] - The value to increment
* @param {number[]} [skip=[]] - The values to skip
* @returns {number[]} Array of number
*
* @function range
* @memberof Maths
*/
export function range(start, end, step = 1, skip = []) {
const arr = [];
Expand Down
3 changes: 3 additions & 0 deletions src/subtraction.js → src/Maths/subtraction.js
Expand Up @@ -9,6 +9,9 @@
*
* @param {...number} numbers - the numbers to subtraction
* @returns {number}
*
* @function subtraction
* @memberof Maths
*/
export function subtraction(...numbers) {
if (!numbers.length) return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/sum.js → src/Maths/sum.js
Expand Up @@ -8,6 +8,9 @@
*
* @param {...number} numbers - the numbers to sum
* @returns {number}
*
* @function sum
* @memberof Maths
*/
export function sum(...numbers) {
return numbers.reduce((acc, curr) => acc + curr, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/SortingAlgorithms/index.js
@@ -1,3 +1,4 @@
import { bogoSort } from "./bogoSort.js";
import { selectionSort } from "./selectionSort.js";

/**
Expand All @@ -9,5 +10,6 @@ import { selectionSort } from "./selectionSort.js";
* @namespace SortingAlgorithms
*/
export {
bogoSort,
selectionSort,
};
42 changes: 2 additions & 40 deletions src/index.js
@@ -1,5 +1,6 @@
import * as DOM from "./DOM/index.js";
import * as Games from "./Games/index.js";
import * as Maths from "./Maths/index.js";
import * as SortingAlgorithms from "./SortingAlgorithms/index.js";

import { allCharactersSame } from "./allCharactersSame.js";
Expand All @@ -14,56 +15,37 @@ import { arraySortAscending } from "./arraySortAscending.js";
import { arraySortAscendingObject } from "./arraySortAscendingObject.js";
import { arraySortDescending } from "./arraySortDescending.js";
import { arraySortDescendingObject } from "./arraySortDescendingObject.js";
import { average } from "./average.js";
import { binary2Decimal } from "./binary2Decimal.js";
import { BinarySearchTree, BinarySearchTreeInstance } from "./BinarySearchTree.js";
import { stringToCamelCase, camelCaseToNormal } from "./camelCase.js";
import { stringToCapitalize, capitalizeToNormal } from "./capitalizeCase.js";
import { clamp } from "./clamp.js";
import { clone } from "./clone.js";
import { compare2Objects } from "./compare2Objects.js";
import { decimal2Binary } from "./decimal2Binary.js";
import { degreesToRadians } from "./degreesToRadians.js";
import { division } from "./division.js";
import { divideEvenly } from "./divideEvenly.js";
import { EventSystem, EventSystemInstance } from "./EventSystem.js";
import { Fibonacci, fibonacciSequence, fibonacciUntil, fibonacciCustomSequence, recursiveFibonacci } from "./Fibonacci.js";
import { FIFO } from "./FIFO.js";
import { getDate } from "./getDate.js"; // import { getTime, getMilliseconds, getSeconds, getMinutes, getHours, getDay, getWeekDay, getWeek, getMonth, getYear, getDateFormatted } from "./getDate.js";
import { getPositionWithAngleDistance } from "./getPositionWithAngleDistance.js";
import { getUrlParameter } from "./getUrlParameter.js";
import { getVersion } from "./getVersion.js";
import { invertedLerp } from "./invertedLerp.js";
import { invertSentence, invertWords } from "./invertText.js";
import { isEven, isOdd } from "./isEvenOdd.js";
import { isMultipleOf } from "./isMultipleOf.js";
import { isNarcissisticNumber } from "./isNarcissisticNumber.js";
import { isFalsy, isTruthy } from "./isTruthyFalsy.js";
import { stringToKebabCase, kebabCaseToNormal } from "./kebabCase.js";
import { lerp } from "./lerp.js";
import { and, or, xor } from "./logicalOperators.js";
import { LIFO } from "./LIFO.js";
import { makeNegative } from "./makeNegative.js";
import { map } from "./map.js";
import { median } from "./median.js";
import { mode } from "./mode.js";
import { multiplication } from "./multiplication.js";
import { radiansToDegrees } from "./radiansToDegrees.js";
import { randomColor, randomColor0X, randomRGBColor, randomRGBAColor } from "./randomColor.js";
import { randomNumber, randomInt, randomFloat } from "./randomNumber.js";
import { randomString } from "./randomString.js";
import { randomWalk1D, randomWalk2D, randomWalk3D } from "./randomWalk.js";
import { range } from "./range.js";
import { stringToScreamingSnakeCase, screamingSnakeCaseToNormal } from "./screamingSnakeCase.js";
import { stringToSnakeCase, snakeCaseToNormal } from "./snakeCase.js";
import { subtraction } from "./subtraction.js";
import { sum } from "./sum.js";
import { topDownCarMovimentation } from "./topDownCarMovimentation.js";
import { Vector2 } from "./Vector2.js";

export {
DOM,
Games,
Maths,
SortingAlgorithms,

BinarySearchTree, BinarySearchTreeInstance,
Expand All @@ -83,44 +65,24 @@ export {
arrayShuffle,
arraySortAscending, arraySortAscendingObject,
arraySortDescending, arraySortDescendingObject,
average,
binary2Decimal,
stringToCamelCase, camelCaseToNormal,
stringToCapitalize, capitalizeToNormal,
clamp,
clone,
compare2Objects,
decimal2Binary,
degreesToRadians,
division,
divideEvenly,
getDate, // getTime, getMilliseconds, getSeconds, getMinutes, getHours, getDay, getWeekDay, getWeek, getMonth, getYear, getDateFormatted,
getPositionWithAngleDistance,
getUrlParameter,
getVersion,
invertedLerp,
invertSentence, invertWords,
isEven, isOdd,
isMultipleOf,
isNarcissisticNumber,
isFalsy, isTruthy,
stringToKebabCase, kebabCaseToNormal,
lerp,
and, or, xor, // logicalOperators
makeNegative,
map,
median,
mode,
multiplication,
radiansToDegrees,
randomColor, randomColor0X, randomRGBColor, randomRGBAColor,
randomNumber, randomInt, randomFloat,
randomString,
randomWalk1D, randomWalk2D, randomWalk3D,
range,
stringToScreamingSnakeCase, screamingSnakeCaseToNormal,
stringToSnakeCase, snakeCaseToNormal,
subtraction,
sum,
topDownCarMovimentation,
};
2 changes: 1 addition & 1 deletion src/topDownCarMovimentation.js
@@ -1,4 +1,4 @@
import { clamp } from "./clamp.js";
import { clamp } from "./Maths/clamp.js";

/**
* Updates a position, rotation and speed of a car in the top down view
Expand Down

0 comments on commit c982f09

Please sign in to comment.