JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
const decomp = number => {
// function that adds the dividers of a number to a "dividers object"
const subdecomp = (number, subdividers) => {
let remainder = number
// from 2 to square root of the number
for (x = 2; x <= Math.sqrt(number); x++) {
// check if it can divide the number
if (remainder % x === 0) {
// add it as a key to a results object
if (!subdividers[x]) subdividers[x] = 0;
// while it can be a divisor, add +1 to the key and update number
while (remainder % x === 0) {
subdividers[x]++;
remainder = remainder / x;
}
}
}
// if after all there's still a remaining number, it is a divisor too
if (remainder > 1) {
if (!subdividers[remainder]) subdividers[remainder] = 1;
else subdividers[remainder] += 1;
}
return subdividers;
}
// initial dividers: none!
let dividers = {}
// calculate the dividers for each number used in the factorial
for (let x = 2; x <= number; x++)
dividers = subdecomp(x, dividers);
// generate a html string with the result
return Object.keys(dividers).reduce((acc, curr) => dividers[curr] === 1
? `${acc} ${curr}`
: `${acc} ${curr}<sup>${dividers[curr]}</sup>`
, `decomp(${number}) = `);
}
document.write(`
${decomp(3)}<br><br>
${decomp(12)}<br><br>
${decomp(22)}<br><br>
${decomp(22)}<br><br>
${decomp(141)}<br><br>
${decomp(1011)}<br><br>
`);
Also see: Tab Triggers