Update
This commit is contained in:
parent
275c83d379
commit
793eff5870
19 changed files with 2117 additions and 1835 deletions
|
@ -16,6 +16,53 @@ In the past JavaScript was only a **[client](client.md) side** scripting languag
|
|||
|
||||
TODO: some more shit
|
||||
|
||||
## Examples
|
||||
|
||||
Below is our standardized [divisor tree](divisor_tree.md) program written in browser JavaScript:
|
||||
|
||||
```
|
||||
<html> <head> <script>
|
||||
|
||||
// recursive function, returns divisor tree of x as a string
|
||||
function divisorTreeStr(x)
|
||||
{
|
||||
let a = -1, b = -1;
|
||||
let s = "";
|
||||
|
||||
for (let i = 2; i <= x / 2; i++) // find closest divisors
|
||||
if (x % i == 0)
|
||||
{
|
||||
a = i;
|
||||
b = x / i;
|
||||
|
||||
if (b <= a)
|
||||
break;
|
||||
}
|
||||
|
||||
s += "("
|
||||
|
||||
s += a > 1 ?
|
||||
divisorTreeStr(a) + " " + x + " " + divisorTreeStr(b) : x;
|
||||
|
||||
return s + ")";
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
while (true) // main loop, read numbers from the user
|
||||
{
|
||||
let x = parseInt(prompt("enter a number:"));
|
||||
|
||||
if (isNaN(x) || x < 0 || x >= 1000)
|
||||
break;
|
||||
|
||||
console.log(divisorTreeStr(x));
|
||||
}
|
||||
}
|
||||
|
||||
</script> </head> <body onload="main()"> </body> </html>
|
||||
```
|
||||
|
||||
## JavaScript Fun
|
||||
|
||||
Here let be recorded funny code in this glorious language.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue