๐พ ็จๅผ๏ผ 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! }
}
}
[1, 2, 3].allElementsEqual // F
[1, 1, 1].allElementsEqual // T
[1].allElementsEqual // T
([] as! [Int]).allElementsEqual // T
["ya", "ya", "ya"].allElementsEqual // T