[Solved] How can I make my JavaScript code more DRY? [closed]

[ad_1] Assuming the myFunction series of functions aren’t used elsewhere, you’d do: var addChangeListener = function(elem, hexInput) { elem.onchange = function() { hexInput.value = elem.value; } }; const elements = { ‘colorpicker01′:’hexinput01’, ‘colorpicker02′:’hexinput02’, ‘colorpicker03′:’hexinput03’} for(elemName in elements) { const elem = document.getElementById(elemName); const hexInput = document.getElementById(elements[elemName]); addChangeListener(elem, hexInput); } And if you need to reuse … Read more

[Solved] duplicate individual paragraphs in txt file

[ad_1] Use: for i in range(0,150): print(“echo update \necho snapshot \necho gall \necho clearobj”) print(“echo read rot_”+”%03d”%i+”.speck \n”) “%03d”%a in Python2 converts to a three digit string. 1 [ad_2] solved duplicate individual paragraphs in txt file

[Solved] Finding regular expression with at least one repetition of each letter

[ad_1] You could find all substrings of length 4+, and then down select from those to find only the shortest possible combinations that contain one of each letter: s=”AAGTCCTAG” def get_shortest(s): l, b = len(s), set(‘ATCG’) options = [s[i:j+1] for i in range(l) for j in range(i,l) if (j+1)-i > 3] return [i for i … Read more

[Solved] Repeating Characters in the Middle of a String

[ad_1] def repeat_middle(text): a, b = divmod(len(text) – 1, 2) middle = text[a:a + b + 1] exclamations=”!” * len(middle) return ‘{}{}{}’.format(exclamations, middle * len(text), exclamations) >>> print repeat_middle(“abMNcd”) !!MNMNMNMNMNMN!! >>> print repeat_middle(“abMcd”) !MMMMM! [ad_2] solved Repeating Characters in the Middle of a String