RotaCloud
by IPWright83
HTML
<iframe id="frame" width="800" height="800"></iframe>
JavaScript
const url = "https://custom.rotacloud.com/developer-challenge/";
const num1 = 467693941;
const num2 = 588250039;
/**
* Finds the factors for a given number
*/
const findFactors = (value) => {
const root = Math.sqrt(value);
const largest = Math.floor(root);
const factors = [];
for (let i = 1; i <= largest; i++) {
if (value % i === 0) {
factors.push(i);
factors.push(value / i);
}
}
return factors;
};
/**
* Finds the set of values that exist in both the arrays
*/
const findMatches = (set1, set2) => {
const results = [];
for (let i = 0; i < set1.length; i++) {
const value = set1[i];
if (set2.indexOf(value) !== -1) {
results.push(value);
}
}
return results;
}
/**
* Finds the largest value within a set
*/
const findLargestValue = (values) => {
let maxValue = 0;
if (values.length === 0) {
return 0;
}
for (let i = 0; i < values.length; i++) {
const value = values[i];
if (value > maxValue) {
maxValue = value;
}
}
return maxValue;
}
/**
* Finds the largest common demoniator for 2 numbers
*/
const findLargestDenominator = (num1, num2) => {
const num1Factors = findFactors(num1);
const num2Factors = findFactors(num2);
const matchingFactors = findMatches(num1Factors, num2Factors);
const largestFactor = findLargestValue(matchingFactors);
return largestFactor;
};
/**
* Scrapes the values from the RotaCloud developer challenge #1
*/
const scrapeValues = () => {
const frame = document.getElementById('frame');
const doc = frame.contentDocument || frame.contentWindow.document;
const elements = doc.getElementsByTagName("b");
const num1 = parseInt(elements[0].textContent);
const num2 = parseInt(elements[1].textContent);
return [num1, num2];
}
const submitValue = (value) => {
const doc = document.getElementById('frame');
const inputs = doc.getElementsByTagName("input");
inputs[0].value = value;
...