arr.allElementsEqual

ๆชขๆŸฅๆ˜ฏไธๆ˜ฏๆ‰€ๆœ‰ๅ…ƒ็ด ้ƒฝ็›ธ็ญ‰ใ€‚

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

extension Array where Element: Equatable {
    /// `array.allElementsEqual`
    public var allElementsEqual: Bool {
        // always true for empty arrays
        guard first != nil else { return true }
        return dropFirst().allSatisfy { $0 == first! }
    }
}

Last updated