Skip to content

Instantly share code, notes, and snippets.

def StringReduction(str)
# code goes here
hash = {"ab":"c", "ac":"b", "bc":"a",
"ba":"c", "ca":"b", "cb":"a"}
count = 0
while str != str[0]*str.length
if hash.has_key? :"#{str[count..count+1]}"
str = str.sub(str[count..count+1], hash[:"#{str[count..count+1]}"])
count = 0
def WordSplit(strArr)
# code goes here
dict = strArr[1].split(",")
for i in dict
for j in dict
if i+j == strArr[0]
return "#{i}, #{j}"
end
end
const pointlessFunction = (input: string): string => {
let oneToThreeObj = {
1: "one", 2: "two", 3: "three"
};
let output = "";
[...input].forEach((char)=>{
// ts-ignore
if (char in oneToThreeObj) output+=oneToThreeObj[char];
});
@omokehinde
omokehinde / isValidString.py
Last active June 2, 2022 00:11
Write a function that returns True or False if the string contains opening and closing brackets in the right order
def isValid(s):
bracket_dic = {
"[":"]",
"{":"}",
"(":")"
}
open_bracket = []
for i in s:
if i not in bracket_dic and len(open_bracket) == 0: return False
@omokehinde
omokehinde / isValid.js
Created June 2, 2022 00:19
A function that checks if a string containing brackets is valid.
let isValid = (s) => {
let bracket_obj = {
"[":"]",
"(":")",
"{":"}"
};
let open_brackets = [];
for (let i = 0; i < s.length; i++) {
if (s[i] in bracket_obj) {
open_brackets.push(s[i]);
@omokehinde
omokehinde / rotated.py
Last active November 7, 2022 15:29
function that takes 2 lists as arguments and returns True if the list are rotated version of each other or False otherwise.
# A function that takes 2 lists as arguments and returns True if the list are rotated version of each other or False otherwise.
def rotated(list1, list2):
if len(list1) != len(list2) or list1[0] == list2[0]:
return False
first_elem_list1 = list1[0]
if first_elem_list1 in list2:
index_first_elem_list2 = list2.index(first_elem_list1)
else: return False