export class Bag { public canContain : Map < Bag , number > = new Map ( ) ; public static create = ( color ) : Bag => new Bag ( color ) ; public constructor ( public color ) { } /**
     * For Part 1
     */ public canEventuallyContain ( bag ) { return ( this . canContain . has ( bag ) || [ ... this . canContain . keys ( ) ] . some ( ( b ) => b . canEventuallyContain ( bag ) ) ) ; } /**
     * For Part 2
     */ public howManyBagsCanItContain ( ) { return [ ... this . canContain . entries ( ) ] . reduce ( ( a , [ b , c ] ) => a + c + c * b . howManyBagsCanItContain ( ) , 0 ) ; } }