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.159 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.158 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.157 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.156 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.155 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.154 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.153 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.152 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.151 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.150 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.149 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.148 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.147 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.146 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.145 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.144 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.143 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.142 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.141 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.140 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts