.allElementsSameLength

ๆชขๆŸฅๆ˜ฏๅฆๆ‰€ๆœ‰ๅ…ƒ็ด  (ไธ€ๅˆ—่ณ‡ๆ–™) ้ƒฝ็ญ‰้•ทใ€‚

โญ๏ธ ๆณจๆ„๏ผš้€™ๆ˜ฏ Collection ็š„ๆ“ดๅฑ•๏ผŒไธๆ˜ฏ Array ็š„ใ€‚

๐Ÿ’พ ็จ‹ๅผ๏ผš replit

// extension primarily for array of arrays
extension Collection where Element: Collection {
    /// all elements (rows) are of the some length
    /// - `[[1,2], [3,4]].allElementsSameLength == true`
    public var allElementsSameLength: Bool {
        guard !isEmpty else { return true }
        return dropFirst().allSatisfy { $0.count == first!.count }
    }
}

Last updated