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 []
@meekg33k
meekg33k / learning-content-schema-improved.js
Last active Mar 21, 2021
Flattened tree hierarchy for learning content schema
View learning-content-schema-improved.js
{
byId: {
'entity-id': {
//Any of Class, Subject, Module or any other entity
}
},
subjects: {
byClass: {
'class-id-1': ['class-id-1-subject-id-1', 'class-id-1-subject-id-2',...],
'class-id-2': ['class-id-2-subject-id-1', 'class-id-2-subject-id-2',...],
@meekg33k
meekg33k / learning-content-schema.js
Created Sep 28, 2020
Tree abstraction of learning-content schema
View learning-content-schema.js
[
{
id: 'class-1',
subjects: [
{
id: 'subject-1-class-1',
modules: [
{
id: 'module-1-subject-1-class-1',
...
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;
}