* chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
3.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
a7f4d8f2483413a6ce226cac | Roman Numeral Converter | 5 | 16044 | roman-numeral-converter |
--description--
Convert the given number into a roman numeral.
All roman numerals answers should be provided in upper-case.
--hints--
convertToRoman(2)
should return the string II
.
assert.deepEqual(convertToRoman(2), 'II');
convertToRoman(3)
should return the string III
.
assert.deepEqual(convertToRoman(3), 'III');
convertToRoman(4)
should return the string IV
.
assert.deepEqual(convertToRoman(4), 'IV');
convertToRoman(5)
should return the string V
.
assert.deepEqual(convertToRoman(5), 'V');
convertToRoman(9)
should return the string IX
.
assert.deepEqual(convertToRoman(9), 'IX');
convertToRoman(12)
should return the string XII
.
assert.deepEqual(convertToRoman(12), 'XII');
convertToRoman(16)
should return the string XVI
.
assert.deepEqual(convertToRoman(16), 'XVI');
convertToRoman(29)
should return the string XXIX
.
assert.deepEqual(convertToRoman(29), 'XXIX');
convertToRoman(44)
should return the string XLIV
.
assert.deepEqual(convertToRoman(44), 'XLIV');
convertToRoman(45)
should return the string XLV
.
assert.deepEqual(convertToRoman(45), 'XLV');
convertToRoman(68)
should return the string LXVIII
assert.deepEqual(convertToRoman(68), 'LXVIII');
convertToRoman(83)
should return the string LXXXIII
assert.deepEqual(convertToRoman(83), 'LXXXIII');
convertToRoman(97)
should return the string XCVII
assert.deepEqual(convertToRoman(97), 'XCVII');
convertToRoman(99)
should return the string XCIX
assert.deepEqual(convertToRoman(99), 'XCIX');
convertToRoman(400)
should return the string CD
assert.deepEqual(convertToRoman(400), 'CD');
convertToRoman(500)
should return the string D
assert.deepEqual(convertToRoman(500), 'D');
convertToRoman(501)
should return the string DI
assert.deepEqual(convertToRoman(501), 'DI');
convertToRoman(649)
should return the string DCXLIX
assert.deepEqual(convertToRoman(649), 'DCXLIX');
convertToRoman(798)
should return the string DCCXCVIII
assert.deepEqual(convertToRoman(798), 'DCCXCVIII');
convertToRoman(891)
should return the string DCCCXCI
assert.deepEqual(convertToRoman(891), 'DCCCXCI');
convertToRoman(1000)
should return the string M
assert.deepEqual(convertToRoman(1000), 'M');
convertToRoman(1004)
should return the string MIV
assert.deepEqual(convertToRoman(1004), 'MIV');
convertToRoman(1006)
should return the string MVI
assert.deepEqual(convertToRoman(1006), 'MVI');
convertToRoman(1023)
should return the string MXXIII
assert.deepEqual(convertToRoman(1023), 'MXXIII');
convertToRoman(2014)
should return the string MMXIV
assert.deepEqual(convertToRoman(2014), 'MMXIV');
convertToRoman(3999)
should return the string MMMCMXCIX
assert.deepEqual(convertToRoman(3999), 'MMMCMXCIX');
--seed--
--seed-contents--
function convertToRoman(num) {
return num;
}
convertToRoman(36);
--solutions--
function convertToRoman(num) {
var ref = [['M', 1000], ['CM', 900], ['D', 500], ['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]];
var res = [];
ref.forEach(function(p) {
while (num >= p[1]) {
res.push(p[0]);
num -= p[1];
}
});
return res.join('');
}