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
18 changes: 17 additions & 1 deletion src/brackets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
34 changes: 33 additions & 1 deletion src/roman-numerals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 15 additions & 1 deletion src/transpose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;