Sha256: bc9ee3094f1369015f47281f65f545b1f55809c3f4db07afef2cbf2d9c436890

Contents?: true

Size: 728 Bytes

Versions: 133

Compression:

Stored size: 728 Bytes

Contents

export default class Triangle {
    rows: number[][]
    lastRow: number[]

    constructor(rows: number) {
        this.rows = this.fillRows(rows)
        this.lastRow = this.rows[this.rows.length - 1]
    }

    newRow(prevRow: number[]) {
        let prev = 0
        const nextRow = []
        for (const x of prevRow) {
            nextRow.push(prev + x)
            prev = x
        }
        nextRow.push(1)
        return nextRow
    }

    fillRows(rows: number) {
        const result = []
        let prevRow: number[] = []
        for (let x = 0; x < rows; x++) {
            const nextRow = this.newRow(prevRow)
            result.push(nextRow)
            prevRow = nextRow
        }
        return result
    }

}

Version data entries

133 entries across 133 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.138 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.137 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.136 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.135 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.134 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.133 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.132 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.131 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.130 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.129 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.128 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.127 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.126 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.125 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.124 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.123 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.122 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.121 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.120 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts