Skip to content

Commit

Permalink
adding new 2 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alieldeba committed Jun 24, 2022
1 parent 7c910d4 commit 79bf9d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions project/ts/functionality/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import randomNumber from "./randoms/randomNumber";
import removeDuplicate from "./arrays/removeDuplicate";
import reverseString from "./strings/reverseString";
import reverseNumber from "./numbers/reverseNumber";
import addCommas from "./numbers/addCommas";
import shuffle from "./arrays/shuffle";
import randomString from "./randoms/randomString";
import randomColor from "./randoms/randomColor";
Expand All @@ -36,6 +37,7 @@ import getDays from "./user/getDays";
import getHours from "./user/getHours";
import getMinutes from "./user/getMinutes";
import getSeconds from "./user/getSeconds";
import getBirthDay from "./user/getBirthDay";
import select from "./dom/select";

const functionality = {
Expand All @@ -54,6 +56,7 @@ const functionality = {
randomElementFrom,
randomHex,
randomNumber,
addCommas,
removeDuplicate,
reverseString,
reverseNumber,
Expand All @@ -75,6 +78,7 @@ const functionality = {
getHours,
getSeconds,
getMinutes,
getBirthDay,
select,
};

Expand Down
9 changes: 9 additions & 0 deletions project/ts/functionality/numbers/addCommas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Returns Number With Commas To Facilitate Reading | e.g 1000000 => 1,000,000
*
* @param {number} number
* @returns {string}
*/
export default function addCommas(number: number): string {
return number.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
}
11 changes: 11 additions & 0 deletions project/ts/functionality/user/getBirthDay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Returns the Age From a Given Year | e.g 2007 -> 15
*
* @param {number} year
* @returns {number}
*/
export default function getBirthDay(year: number): number {
var currentDate = new Date();
var currentYear = currentDate.getFullYear();
return currentYear - year;
}

0 comments on commit 79bf9d0

Please sign in to comment.