Skip to content

Instantly share code, notes, and snippets.

@mjmeilahn
mjmeilahn / PrintDuplicates.py
Last active June 16, 2023 23:46
Prints duplicates from a list.
# Print all duplicates from a list.
lis = [1,3,2,5,6,7,3,3,1,4,4]
def printDuplicates(lis):
results = []
for num in lis:
dupe = lis.count(num) > 1
@mjmeilahn
mjmeilahn / LogDuplicates.js
Last active June 16, 2023 23:34
Logs all duplicate numbers in an array.
// Log all duplicate numbers in an array.
const arr = [1,3,2,5,6,7,3,3,1,4,4]
const logDuplicates = arr => {
const results = []
arr.map(num => {
const dupe = arr.filter(i => i === num).length > 1
@mjmeilahn
mjmeilahn / ValidClosures.py
Last active June 5, 2023 22:15
Python: Valid String Closures.
"""
Return TRUE or FALSE whether the string has valid closures.
A valid closure can be: () or ({}) or []({}).
An invalid closure interrupts open/close characters.
Each opener character must have a closer character.
Each closer character must have an opener character.
"""
patterns = {
'{': '}',
@mjmeilahn
mjmeilahn / CompareStrings.py
Last active May 3, 2023 23:34
Python: Comparing Strings
# Compare TWO strings and return TRUE if the 2nd String only requires one change to match the original string.
# Otherwise return FALSE.
def compareStrings(orig, diff):
count = 0
for char in list(diff):
match = [i for i in list(orig) if i == char]
if len(match) == 1: count += 1
@mjmeilahn
mjmeilahn / PerformanceLogs.py
Last active May 3, 2023 23:32
Python: Performance Log Sequences
"""
Return an array of User IDs that have logged the correct actions
taken at least once in the performance logs with this sequence:
A -> B -> C
"""
logs = [
{ 'userID': 1, 'action': 'C' },
{ 'userID': 2, 'action': 'B' },
@mjmeilahn
mjmeilahn / validClosures.js
Created February 14, 2023 22:06
JS: Valid String Closures.
/*
Return TRUE or FALSE whether the string has valid closures.
A valid closure can be: () or ({}) or []({}).
An invalid closure interrupts open/close characters.
Each opener character must have a closer character.
Each closer character must have an opener character.
*/
const patterns = {
'{': '}',
@mjmeilahn
mjmeilahn / compareStrings.js
Last active March 15, 2023 18:14
JS: Comparing Strings
// Compare TWO strings and return TRUE if the 2nd String
// only requires one change to match the original string.
// Otherwise return FALSE.
const compareStrings = (orig, diff) => {
let count = 0
diff.split('').map(char => {
const match = orig.split('').find(i => i === char)
@mjmeilahn
mjmeilahn / performanceLogs.js
Last active March 17, 2023 15:25
JS: Performance Log Sequence
// Return an array of User IDs that have
// logged the correct actions taken at least once
// in the performance logs with this exact sequence: A => B => C
const logs = [
{ userID: 1, action: 'C' },
{ userID: 2, action: 'B' },
{ userID: 3, action: 'B' },
{ userID: 2, action: 'A' },
@mjmeilahn
mjmeilahn / objectArrayManipulation.js
Created May 12, 2020 17:19
JS: Object & Array Manipulation
// Assume a large array as the main argument with the following schema and manipulate accordingly.
// EXAMPLE SCHEMA:
// name: String
// weight: Number
// price: Number
// size: Number
// id: Number
@mjmeilahn
mjmeilahn / fizzbuzz.js
Last active May 29, 2020 15:47
JS: Fizzbuzz Function
// DESCRIPTION
// Counting from 0 to 100, print out each number in the console.
// RULES
// 1. If the number is a multiple of 3, print "fizz" instead of the number.
// 2. If the number is a multiple of 5, print "buzz" instead of the number.
// 3. If the number is a multiple of both 3 and 5, print "fizzbuzz" in place of the number.
// 4. Otherwise just print the number itself.
// 5. Each entry should be printed on a new line.