diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..758ef57 Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..f1fc301 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/brackets/index.js b/src/brackets/index.js index 96b6766..5590fb7 100644 --- a/src/brackets/index.js +++ b/src/brackets/index.js @@ -4,6 +4,35 @@ * @param {string} str The string of brackets. * @returns {"valid" | "invalid"} Whether or not the string is valid. */ -function isValid(str) {} + +function isValid(str) { + let stack = [] + for(let i in str) { + let x = stack.length - 1 + if(str[i]=="(" || str[i]=="{" || str[i]=="[") { + stack.push(str[i]) + } + else{ + if(str[i]== ")" && stack[x]=="(") { + stack.pop() + } + else if(str[i]=="}" && stack[x]=="{") { + stack.pop() + } + else if(str[i]=="]" && stack[x]=="[") { + stack.pop() + } + else{ + return "invalid" + } + } + } + return stack.length > 0 ? "invalid" : "valid" +} module.exports = isValid; + + + + + diff --git a/src/roman-numerals/index.js b/src/roman-numerals/index.js index 38afb19..9f4d99e 100644 --- a/src/roman-numerals/index.js +++ b/src/roman-numerals/index.js @@ -4,6 +4,35 @@ * @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 stack = []; + let total = 0; + + const romanNumerals = { + I: 1, + V: 5, + X: 10, + L: 50, + C: 100, + D: 500, + M: 1000, + }; + + for (let i = 0; i < roman.length; i++) { + const currentSymbol = roman[i]; + const currentValue = romanNumerals[currentSymbol]; + const nextValue = romanNumerals[roman[i + 1]]; + + if (nextValue && currentValue < nextValue) { + total -= currentValue; + } else { + total += currentValue; + } + } + + return total; +} + module.exports = romanToDecimal; diff --git a/src/transpose/index.js b/src/transpose/index.js index adec201..64a49c5 100644 --- a/src/transpose/index.js +++ b/src/transpose/index.js @@ -4,6 +4,23 @@ * @param {number[]} array The array to transpose * @returns {number[]} The transposed array */ -function transpose(array) {} -module.exports = transpose; +function transpose(array) { + const numRows = array.length; + const numCols = array[0].length; + + const transposed = new Array(numCols).fill(null).map(() => new Array(numRows)); + + for (let row = 0; row < numRows; row++) { + for (let col = 0; col < numCols; col++) { + transposed[col][row] = array[row][col]; + } + } + + return transposed; + } + + + + module.exports = transpose; + \ No newline at end of file