Skip to content
Open
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
22 changes: 22 additions & 0 deletions maths/binary_to_Decimal_conversion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @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;
}


27 changes: 27 additions & 0 deletions maths/prime_check.ts
Original file line number Diff line number Diff line change
@@ -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`);
}