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.180 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/pascals-triangle/pascals-triangle.example.ts