A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Prime Number in Typescript page! Here, you'll find the source code for this program as well as a description of how the program works.
function isPrime(num: number): boolean {
if (num < 2) {
return false;
}
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
function main() {
if (process.argv.length !== 3) {
console.log('Usage: please input a non-negative integer');
return;
}
const inputNum = parseFloat(process.argv[2]);
if (isNaN(inputNum) || inputNum < 0 || inputNum % 1 !== 0) {
console.log('Usage: please input a non-negative integer');
return;
}
if (isPrime(inputNum)) {
console.log('prime');
} else {
console.log('composite');
}
}
main();
Prime Number in Typescript was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.