Skip to content

Instantly share code, notes, and snippets.

Avatar
🇮🇴
It's all 0's and 1's

Uduak 'Eren meekg33k

🇮🇴
It's all 0's and 1's
View GitHub Profile
@meekg33k
meekg33k / parsePostContent.js
Created Mar 2, 2021
Code snippet for Medium's algorithm problem on how to apply deltas to a post structure.
View parsePostContent.js
/** Ideally this will be declared in a constants module */
const ADD_PARAGRAPH_DELTA = "addParagraph";
const DELETE_PARAGRAPH_DELTA = "deleteParagraph";
const UPDATE_PARAGRAPH_DELTA = "updateParagraph";
let sectionParagraphIndices = [];
/**
* @param {string} delta
* @param {Array} paragraphs
@meekg33k
meekg33k / returnMostFrequentlyUsedWords.js
Created Jan 18, 2021
Algorithm to return most frequently used words
View returnMostFrequentlyUsedWords.js
const wordsToExclude = ['and', 'he', 'the', 'to', 'is', 'Jack', 'Jill']
const literatureText = 'Jack and Jill went to the market to buy bread and cheese. Cheese is Jack\'s and Jill\'s favorite food'
const getTokenizedWords = (word) => {
if (!word || word === '') return []
return word.split(/\W+/)
}
const getValidTokenizedWords = (words, excludedWords) => {
if (!words || words.length === 0) return []
View findWordsInBoard.js
const findWordsInBoard = (board, listOfWords) => {
/* Returns a subset of words in listOfWords
* that can be formed from characters on board
*/
};
const BOARD = [
['g','r','t','a'],
['n','i','a','e'],
['d','k','w','r'],
['t','e','l','v']
@meekg33k
meekg33k / findMinTimeDiff.js
Last active Aug 22, 2020
Function to find minimum time difference between any two time points in a list
View findMinTimeDiff.js
const findMinTimeDiff = (listOfTimes) => {
/** Returns the minimum time difference in minutes between any two points **/
}
findMinTimeDiff(['00:00', '00:01']); //should return 1 minute
findMinTimeDiff(['00:03', '03:12', '00:00', '03:14']); //should return 2 minutes
findMinTimeDiff(['13:20', '00:01', '14:00', '18:05', '13:28']); //should return 8 minutes
findMinTimeDiff(['00:00', '00:02', '23:59', '00:05']); //should return 1 minute
View is-cat-type-guard.ts
const isCat = (animal: Animal): animal is Cat => {
//Hey compiler, this animal is a Cat
return true;
}
@meekg33k
meekg33k / check-animal-type-using-type-assertion.ts
Last active Jan 17, 2020
Logic to check if an animal type using type assertion https://medium.com/p/177b4a654ef6
View check-animal-type-using-type-assertion.ts
const isCat = (animal: Animal):boolean => {
return (animal as Cat).meow
}
const isDog = (animal: Animal): boolean => {
return (animal as Dog).bark
}
View dog-cat-animal-interface.ts
interface Cat {
meow();
walk();
}
interface Dog {
bark();
walk();
}
@meekg33k
meekg33k / is-present-object-final.ts
Last active Mar 26, 2020
Code snippet for TypeScript Type Guards and Generics (Read full article here https://medium.com/p/177b4a654ef6)
View is-present-object-final.ts
const isPresentObject = <T>(arg: T): arg is T => {
if (arg && Object.keys(arg).length > 0) {
return true;
}
return false;
}
View is-present-object-with-generics.ts
type SomeObjectType;
type AnotherObjectType;
type AnyOtherObjectYouWantToAddType;
const isPresentObjectGeneric = <T>(arg: T): boolean => {
if (arg && Object.keys(arg).length > 0) {
return true;
}
return false;
}
View identity-function-with-generics.ts
const identity = <T>(arg: T): T => arg;
identity<string>('someString'); //would return 'someString'
identity<number>(12); //would return 12
identity<boolean>(false); //would return false