diff --git a/src/brackets/index.js b/src/brackets/index.js index 96b6766..d86d81c 100644 --- a/src/brackets/index.js +++ b/src/brackets/index.js @@ -4,6 +4,33 @@ * @param {string} str The string of brackets. * @returns {"valid" | "invalid"} Whether or not the string is valid. */ -function isValid(str) {} +function chechBracket(str){ + let bracket = []; + let opening = '({['; + let closing = ')}]'; + let matching = { + ')': '(', + '}': '{', + ']': '[' + }; -module.exports = isValid; + for(let i = 0; i < str.length; i++){ + console.log(str[i]) + if(opening.includes(str[i])){ + bracket.push(str[i]); + } else if(closing.includes(str[i])){ + const lastBracket = bracket.pop(); + + if(matching[str[i]] != lastBracket){ + return "invalid"; + } + } + + } + if(bracket.length == 0){ + return "valid" + } else{ + return "invalid"; + } +} +console.log(chechBracket("()()()()()")); \ No newline at end of file diff --git a/src/roman-numerals/index.js b/src/roman-numerals/index.js index 38afb19..4e56e62 100644 --- a/src/roman-numerals/index.js +++ b/src/roman-numerals/index.js @@ -4,6 +4,34 @@ * @param {string} roman The all-caps Roman numeral between 1 and 3999 (inclusive). * @returns {number} The decimal equivalent. */ -function romanToDecimal(roman) {} +function Numerals(roman){ + let numeral = { + I: 1, + V: 5, + X: 10, + L: 50, + C: 100, + D: 500, + M: 1000 -module.exports = romanToDecimal; + }; + + let result = 0; + for(let i = 0; i < roman.length; i++){ + + let curSym = numeral[roman[i]] + let nextSym = numeral[roman[i + 1]] + + if( nextSym && nextSym > curSym){ + result += nextSym - curSym + i++ + + }else{ + result += curSym + } + + + } + + return result; +}; diff --git a/src/transpose/index.js b/src/transpose/index.js index adec201..52e58e1 100644 --- a/src/transpose/index.js +++ b/src/transpose/index.js @@ -4,6 +4,11 @@ * @param {number[]} array The array to transpose * @returns {number[]} The transposed array */ -function transpose(array) {} -module.exports = transpose; + +function transpose(arr) { + + let newArr = arr[0].map((item, index) => arr.map(cur => cur[index])) + return newArr; + +} \ No newline at end of file