Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new commit #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
37 changes: 35 additions & 2 deletions src/brackets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
* @param {string} str The string of brackets.
* @returns {"valid" | "invalid"} Whether or not the string is valid.
*/
function isValid(str) {}

module.exports = isValid;
function isValid(str) {
let stack = [];
// For each char in the bracket
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 top = stack.pop();
if( x == ')' && top != '(' ) {
return "invalid";
}
if( x == ']' && top != '[' ) {
return "invalid";
}
if( x == '}' && top != '{' ) {
return "invalid";
}

}

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

};

console.log(isValid("]]"));

module.exports = isValid;
32 changes: 30 additions & 2 deletions src/roman-numerals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

module.exports = romanToDecimal;

function romanToDecimal(roman) {
let romanToDecimal = {
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 currSym = romanToDecimal[roman[i]];
let nextSym = romanToDecimal[roman[i + 1]];

if(nextSym && nextSym > currSym) {
result += nextSym - currSym
i++
} else {
result += currSym
}

};
return result
};


module.exports = romanToDecimal;
7 changes: 5 additions & 2 deletions 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) {}

module.exports = transpose;
function transpose(array) {
return array[0].map((item, index) => array.map((cur) => cur[index]));
};

module.exports = transpose;