In your command-line run the following commands:
brew doctorbrew update
| unitOfWork: IUnitOfWork = UnitOfWorkFactory::makeUnitOfWork('typeorm'); | |
| unitOfWork.start(); | |
| var work = () { | |
| teamRepository = unitOfWork.getRepository(TeamRepository); | |
| teamMemberRepository = unitOfWork.getRepository(TeamMemberRepository); | |
| team = new Team('name'); | |
| teamMember1 = new TeamMember('John'); |
| @Injectable() | |
| export class UnitOfWorkFactory { | |
| private readonly connection: Connection; | |
| constructor(@Inject(TYPES.AsyncDatabaseConnection) connection: Connection) { | |
| this.connection = connection; | |
| } | |
| static makeUnitOfWork(ormType: string): IUnitOfWork { | |
| if (ormType === 'typeorm') { | |
| return new TypeOrmUnitOfWork(this.connection); |
| export class TypeOrmUnitOfWork implements IUnitOfWork { | |
| private readonly asyncDatabaseConnection: Connection; | |
| private readonly queryRunner: QueryRunner; | |
| private transactionManager: EntityManager; | |
| constructor( | |
| @Inject(TYPES.AsyncDatabaseConnection) asyncDatabaseConnection: Connection, | |
| ) { | |
| this.asyncDatabaseConnection = asyncDatabaseConnection; | |
| this.queryRunner = this.asyncDatabaseConnection.createQueryRunner(); |
| export interface IUnitOfWork { | |
| start(): void; | |
| complete(work: () => void): Promise<void>; | |
| getRepository<T>(R: new (transactionManager: any) => T): T; | |
| } |
In your command-line run the following commands:
brew doctorbrew update| function solution($A, $K, $L) { | |
| $maxAliceSum = getMaxSum($A, $K); | |
| $maxBobSum = getMaxSumForBob($A, $K, $L, $maxAliceSum[1]); | |
| return $maxAliceSum[0] + $maxBobSum; | |
| } | |
| function getMaxSum($A, $K) { |
| /** | |
| Stringify null values in the an object | |
| */ | |
| const stringifyNullValues = item => { | |
| const stringifiedItem = Object.keys(item).reduce( | |
| (result, key) => { | |
| result[key] = item[key] || ""; | |
| return result; | |
| }, |
| function mapValues(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| result[key] = fn(obj[key], key); | |
| return result; | |
| }, {}); | |
| } | |
| function pick(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| if (fn(obj[key])) { |