From 28cd012b6a95c3081c2df664d9977819bef6d8b1 Mon Sep 17 00:00:00 2001 From: Muhammad Mukhtar Date: Mon, 30 Jan 2023 15:30:15 +0100 Subject: [PATCH 1/2] submitted --- src/brackets/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/brackets/index.js b/src/brackets/index.js index 96b6766..e61700c 100644 --- a/src/brackets/index.js +++ b/src/brackets/index.js @@ -4,6 +4,22 @@ * @param {string} str The string of brackets. * @returns {"valid" | "invalid"} Whether or not the string is valid. */ -function isValid(str) {} +function isValid(str) { + + let stck = [] + + for(let i = 0; i < str.length; i++){ + let char = stck[stck.length - 1] + if(str[i] == "(" || str[i] == "{" || str[i] == "[") { + stck.push(str[i]); + + } else if ((char == "(" && str[i] == ")") || (char == "{" && str[i] == "}" || (char == "[" && str[i] == "]"))){ + stck.pop(); + }else{ + return "invalid"; + } + } +return stck.length ? "invalid" : "valid"; +} module.exports = isValid; From e6285f073560e7217cc5b223b00be931855a8d71 Mon Sep 17 00:00:00 2001 From: Muhammad Mukhtar Date: Mon, 30 Jan 2023 15:34:25 +0100 Subject: [PATCH 2/2] submit --- src/roman-numerals/index.js | 34 +++++++++++++++++++++++++++++++++- src/transpose/index.js | 16 +++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/roman-numerals/index.js b/src/roman-numerals/index.js index 38afb19..6e08700 100644 --- a/src/roman-numerals/index.js +++ b/src/roman-numerals/index.js @@ -4,6 +4,38 @@ * @param {string} roman The all-caps Roman numeral between 1 and 3999 (inclusive). * @returns {number} The decimal equivalent. */ -function romanToDecimal(roman) {} +function romanToDecimal(roman) { + + const romansValue = {"M":1000, "D":500, "C":100, "L":50, "X":10, "V":5, "I":1}; + + const array = roman.split(''); + + var total = 0; + + var currentValue; + + var nextValue; + + var n = array.length; + + for(let i = 0; i < n; i++){ + + currentValue = romansValue[array[i]]; + + nextValue = romansValue[array[i + 1]]; + + if(currentValue >= nextValue){ + total += (currentValue); + + } else if(currentValue < nextValue){ + total -= (currentValue); + + } else if(currentValue && !nextValue){ + total += currentValue; + } + + } + return total; +} module.exports = romanToDecimal; diff --git a/src/transpose/index.js b/src/transpose/index.js index adec201..45dfb30 100644 --- a/src/transpose/index.js +++ b/src/transpose/index.js @@ -4,6 +4,20 @@ * @param {number[]} array The array to transpose * @returns {number[]} The transposed array */ -function transpose(array) {} +function transpose(array) { + + for (var i = 0; i < array.length; i++) { + + for (var j = 0; j < i; j++) { + + const temp = array[i][j]; + + array[i][j] = array[j][i]; + + array[j][i] = temp; + } + } + +} module.exports = transpose;