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
33 changes: 32 additions & 1 deletion src/brackets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
* @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 = 0; i < str.length; i++) {
let x = str[i];

if ( x == '[' || x == '{' || x == '(') {
stack.push(x);
continue;
}

if (stack.length === 0 )
return "invalid"

const poppedELEMENT = stack.pop();
if (x == ']' && poppedELEMENT != '['){
return "invalid"
}
if (x == '}' && poppedELEMENT != '{') {
return "invalid"
};
if (x == ')' && poppedELEMENT != '(') {
return "invalid"
};


};

return stack.length === 0 ? "valid" : "invalid"
};


module.exports = isValid;
35 changes: 34 additions & 1 deletion src/roman-numerals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
* @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 < 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
};

module.exports = romanToDecimal;






5 changes: 4 additions & 1 deletion src/transpose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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((cur) => cur[index]))

};

module.exports = transpose;