diff --git a/src/brackets/index.js b/src/brackets/index.js index 96b6766..93c4cfa 100644 --- a/src/brackets/index.js +++ b/src/brackets/index.js @@ -4,6 +4,26 @@ * @param {string} str The string of brackets. * @returns {"valid" | "invalid"} Whether or not the string is valid. */ -function isValid(str) {} +function isValid(str) { + let bracket = []; + let opening = "({["; + let closing = ")}]"; + let matching = {")":"(", "]":"[","}":"{" } ; + + for(let i= 0; i< str.length; i++) { + if(opening.includes(str[i])){ + bracket.push(str[i]) + } else if(closing.includes(str[i])) { + let lastBracket= bracket.pop(); + if(matching[str[i]] !== lastBracket) { + return "invalid" + } + } + } + + return bracket.length === 0 ? "valid" : "invalid"; +}; + + module.exports = isValid; diff --git a/src/roman-numerals/index.js b/src/roman-numerals/index.js index 38afb19..2040a6f 100644 --- a/src/roman-numerals/index.js +++ b/src/roman-numerals/index.js @@ -4,6 +4,23 @@ * @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 numeral= {I : 1, V : 5, X : 10, L : 50, C : 100, D : 500, M : 1000} + let result = 0 + for(let i=0; i currLetter) { + result += nextLetter - currLetter + i++ + } else { + + result+= currLetter + } + } + return result +}; + module.exports = romanToDecimal; diff --git a/src/transpose/index.js b/src/transpose/index.js index adec201..f438015 100644 --- a/src/transpose/index.js +++ b/src/transpose/index.js @@ -4,6 +4,9 @@ * @param {number[]} array The array to transpose * @returns {number[]} The transposed array */ -function transpose(array) {} +function transpose(array) { + return array[0].map((item, index)=> array.map( row =>row[index])); + +}; module.exports = transpose;