Skip to content

Instantly share code, notes, and snippets.

import { Helper } from './helper'
import { Observable, combineLatest, Subject } from 'rxjs'
import {
refCount,
scan,
startWith,
switchMapTo,
takeUntil,
publishBehavior,
} from 'rxjs/operators'
export interface IGameState {
id: string
status: GameStatus
selectedLetters: string[]
lifeLeft: number
secretWordLength: number
knownSecretWord: string
timeLeft: number
}
import { GameStatus } from './hangman/model'
import { Helper } from './hangman/helper'
import { timer, Subject } from 'rxjs'
import express from 'express'
import { reactiveHangman } from './hangman/reactive-hangman'
import { StateManager } from './hangman/state-manager'
import { take, distinctUntilKeyChanged } from 'rxjs/operators'
const app = express()
const port = 3000
import { Observable, BehaviorSubject, Subject } from 'rxjs'
import { withLatestFrom } from 'rxjs/operators'
import { deepEqual } from 'assert'
interface IGameState {
status: GameStatus
selectedLetters: string[]
lifeLeft: number
secretWordLength: number
knownSecretWord: string
@imkrish
imkrish / hangman2.ts
Last active September 22, 2018 21:55
function hangman2(secretWords: string, ...letters: string[]) {
return [...secretWords].every(char => letters.includes(char))
}
function hangman(secretWords: string, ...letters: string[]) {
return (
secretWords
.split('')
.sort()
.join() ===
letters
.filter(letter => secretWords.includes(letter))
.sort()
.join()
@imkrish
imkrish / 06-prop.js
Last active September 3, 2017 00:21
06-prop.js
const R = require('ramda')
const customers = [
{ id: 1, name: 'Bill', age: 45, title: 'MR.', email: 'bill@email.com', phoneNumber: 01, company: 'ABC Comp' },
{ id: 2, name: 'Diane', age: 59, email: 'diane@email.com', phoneNumber: 02 },
{ id: 3, name: 'Krish', age: 26, title: 'MR.', phoneNumber: 03, company: 'Apricot' }
]
// const titleProp = R.prop('title')
// const nameProp = R.prop('name')
@imkrish
imkrish / 05-lens-over.js
Created September 2, 2017 23:47
05-lens-over.js
const R = require('ramda')
const products = [...]
const unitCostLens = R.lensProp('unit_cost')
const dollarToNumber = R.pipe(R.tail, Number)
const unitCostDollarToNumber = R.over(unitCostLens, dollarToNumber)
const mapUnitCostDollarToNumber = R.map(unitCostDollarToNumber)
const result = mapUnitCostDollarToNumber(products)
cconsole.log(result)
@imkrish
imkrish / 04-map-filter-sort-reduce.js
Last active September 5, 2017 20:16
04-map-filter-sort-reduce.js
const R = require('ramda')
const products = [...]
// R.map
const productNameProp = R.prop('product_name')
const getProductNameList = R.map(productNameProp)
const mapResult = getProductNameList(products)
// console.log(mapResult)
@imkrish
imkrish / products.json
Last active September 2, 2017 23:00
products.json
[
{
"id": "5968dd23fc13ae04d9000001",
"product_name": "sildenafil citrate",
"supplier": "Wisozk Inc",
"quantity": 261,
"unit_cost": "$10.47"
}, {
"id": "5968dd23fc13ae04d9000002",
"product_name": "Mountain Juniperus ashei",