From 3e18b9af75694a5c72632bb44fc7aeb77f3d9001 Mon Sep 17 00:00:00 2001 From: Preetiraj3697 Date: Fri, 14 Apr 2023 15:38:10 +0530 Subject: [PATCH 1/3] #10 Create binary_to_Decimal_Conversion Method in Maths Function # --- maths/binary_to_Decimal_conversion | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 maths/binary_to_Decimal_conversion diff --git a/maths/binary_to_Decimal_conversion b/maths/binary_to_Decimal_conversion new file mode 100644 index 00000000..467ddc8c --- /dev/null +++ b/maths/binary_to_Decimal_conversion @@ -0,0 +1,25 @@ +/** + * @function binaryToDecimal + * @description Convert the binary to decimal . + * @param {number} binary - The input string + * @return {string} - decimal of binary. + * @example binaryToDecimal('1011') = 11 + * @example binaryToDecimal('1110') = 14 + */ + +function binaryToDecimal(binary: string): number { + let decimal: number = 0; + let power: number = 0; + for (let i = binary.length - 1; i >= 0; i--) { + if (binary[i] === '1') { + decimal += Math.pow(2, power); + } + power++; + } + return decimal; +} + + +const binary: string = '1011'; +const decimal: number = binaryToDecimal(binary); +console.log(`The decimal representation of ${binary} is ${decimal}`); From e96b4681a9cf6c935c89f53ae8eae84c7eabd36d Mon Sep 17 00:00:00 2001 From: Preetiraj3697 Date: Fri, 14 Apr 2023 15:52:21 +0530 Subject: [PATCH 2/3] #10 Create Prime_check.ts in Math function --- maths/prime_check.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 maths/prime_check.ts diff --git a/maths/prime_check.ts b/maths/prime_check.ts new file mode 100644 index 00000000..c158f961 --- /dev/null +++ b/maths/prime_check.ts @@ -0,0 +1,27 @@ +/** + * @function isPrime + * @description program to check if a number is prime or not + * @see [Prime Check](https://www.programiz.com/javascript/examples/prime-number) + * @example Prime Number -> 5,7,11,13,17 + * @param {num} number + */ + +function isPrime(num: number): boolean { + if (num <= 1) { + return false; + } + for (let i = 2; i <= Math.sqrt(num); i++) { + if (num % i === 0) { + return false; + } + } + return true; + } + + +const num: number = 17; +if (isPrime(num)) { + console.log(`${num} is prime`); +} else { + console.log(`${num} is not prime`); +} From 9b7c0ddc8490bc28670e0694c853896fbcc3d64a Mon Sep 17 00:00:00 2001 From: Preetiraj3697 Date: Wed, 19 Apr 2023 15:24:56 +0530 Subject: [PATCH 3/3] update code #125 --- ...y_to_Decimal_conversion => binary_to_Decimal_conversion.ts} | 3 --- maths/prime_check.ts | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) rename maths/{binary_to_Decimal_conversion => binary_to_Decimal_conversion.ts} (77%) diff --git a/maths/binary_to_Decimal_conversion b/maths/binary_to_Decimal_conversion.ts similarity index 77% rename from maths/binary_to_Decimal_conversion rename to maths/binary_to_Decimal_conversion.ts index 467ddc8c..fc52cb9d 100644 --- a/maths/binary_to_Decimal_conversion +++ b/maths/binary_to_Decimal_conversion.ts @@ -20,6 +20,3 @@ function binaryToDecimal(binary: string): number { } -const binary: string = '1011'; -const decimal: number = binaryToDecimal(binary); -console.log(`The decimal representation of ${binary} is ${decimal}`); diff --git a/maths/prime_check.ts b/maths/prime_check.ts index c158f961..8696948b 100644 --- a/maths/prime_check.ts +++ b/maths/prime_check.ts @@ -1,4 +1,4 @@ -/** +/* * @function isPrime * @description program to check if a number is prime or not * @see [Prime Check](https://www.programiz.com/javascript/examples/prime-number)