Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Repeating Decimals by SaintDron
"use strict";
function convert(numerator, denominator) {
let result = [Math.floor(numerator / denominator) + '.'],
numsUsed = ['0_ะพ'];
numerator = numerator % denominator * 10;
while (numerator && !numsUsed.includes(numerator)) {
numsUsed.push(numerator);
result.push(Math.floor(numerator / denominator));
numerator = numerator % denominator * 10;
}
if (numsUsed.includes(numerator)) {
result.splice(numsUsed.indexOf(numerator), 0, '(');
result.push(')');
}
return result.join('');
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(convert(1, 3), "0.(3)")
assert.equal(convert(5, 3), "1.(6)")
assert.equal(convert(3, 8), "0.375")
assert.equal(convert(7, 11), "0.(63)")
assert.equal(convert(29, 12), "2.41(6)")
assert.equal(convert(11, 7), "1.(571428)")
assert.equal(convert(0, 117), "0.")
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
July 26, 2018