Skip to content

Instantly share code, notes, and snippets.

View meekg33k's full-sized 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 March 2, 2021 01:40
Code snippet for Medium's algorithm problem on how to apply deltas to a post structure.
/** 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 January 18, 2021 21:33
Algorithm to return most frequently used words
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 March 21, 2021 08:37
Flattened tree hierarchy for learning content schema
{
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 September 28, 2020 22:08
Tree abstraction of learning-content schema
[
{
id: 'class-1',
subjects: [
{
id: 'subject-1-class-1',
modules: [
{
id: 'module-1-subject-1-class-1',
...
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 August 22, 2020 19:20
Function to find minimum time difference between any two time points in a list
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
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 January 17, 2020 17:17
Logic to check if an animal type using type assertion https://medium.com/p/177b4a654ef6
const isCat = (animal: Animal):boolean => {
return (animal as Cat).meow
}
const isDog = (animal: Animal): boolean => {
return (animal as Dog).bark
}
interface Cat {
meow();
walk();
}
interface Dog {
bark();
walk();
}
@meekg33k
meekg33k / is-present-object-final.ts
Last active July 1, 2022 13:30
Code snippet for TypeScript Type Guards and Generics (Read full article here https://medium.com/p/177b4a654ef6)
const isPresentObject = <T>(arg: T): arg is T => {
if (arg && Object.keys(arg).length > 0) {
return true;
}
return false;
}