Last active
October 22, 2022 09:46
-
-
Save thegabriele97/521d93bf6abada819647c2632bf27458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let n = 0; | |
let primes: number[] = []; // [1, 2, 3, 5] | |
while(primes.length < 10) { | |
++n; | |
let skip = false; | |
for (let i = 1; i < primes.length && !skip; i++) { | |
if (n % primes[i] == 0) { | |
skip = true; | |
} | |
} | |
if (!skip) { | |
primes.push(n); | |
} | |
} | |
let str = "I primi 10 numeri primi sono: "; | |
for (let i = 0; i < primes.length; i++) { | |
str += primes[i] + " "; | |
} | |
console.log(str); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Welcome to the TypeScript Playground, this is a website | |
// which gives you a chance to write, share and learn TypeScript. | |
// You could think of it in three ways: | |
// | |
// - A location to learn TypeScript where nothing can break | |
// - A place to experiment with TypeScript syntax, and share the URLs with others | |
// - A sandbox to experiment with different compiler features of TypeScript | |
let n = 0; | |
let primes: number[] = []; // [1, 2, 3, 5] | |
while(true) { | |
if (primes.length == 10) { | |
break; | |
} | |
++n; | |
let skip = false; | |
for (let i = 1; i < primes.length; i++) { | |
if (n % primes[i] == 0) { | |
skip = true; | |
break; | |
} | |
} | |
if (skip) continue; | |
primes.push(n); | |
} | |
let str = "I primi 10 numeri primi sono: "; | |
for (let i = 0; i < primes.length; i++) { | |
str += primes[i] + " "; | |
} | |
console.log(str); | |
// To learn more about the language, click above in "Examples" or "What's New". | |
// Otherwise, get started by removing these comments and the world is your playground. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment