ๆชขๆฅๆฏไธๆฏๆๆๅ ็ด ้ฝ็ธ็ญใ
๐พ ็จๅผ๏ผ 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
Swift โฉ Array โฉ
allSatisfy(_:)
elementsEqual(_:)
check if all elements of an array have the same value in Swift
similar to .allElementsSameLength.
Last updated 2 years ago