Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/roman-numerals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@
* @param {string} roman The all-caps Roman numeral between 1 and 3999 (inclusive).
* @returns {number} The decimal equivalent.
*/
function romanToDecimal(roman) {}
function romanToDecimal(roman) {
let sum = 0;
let romanNum = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};


for (let i = 0; i < roman.length; i++){


if (romanNum[roman[i]] < romanNum[roman[i+1]]){

sum = sum - romanNum[roman[i]];
} else {
sum = sum + romanNum[roman[i]];
}
}
return sum;
}

module.exports = romanToDecimal;
13 changes: 12 additions & 1 deletion src/transpose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
* @param {number[]} array The array to transpose
* @returns {number[]} The transposed array
*/
function transpose(array) {}
function transpose(array) {
let result = [];

for (let i = 0; i < array[0].length; i++){
let temp = [];
for(let j = 0; j < array.length; j++){
temp.push(array[j][i]);
}
result.push(temp);
}
return result;
}

module.exports = transpose;