Domanda di colloquio di Meta

Find the intersection between 2 NSRanges

Risposte di colloquio

Anonimo

4 nov 2017

Did you manage to finish the question. How many questions did he gave you ?

Anonimo

10 giu 2018

func findIntersection(range1: NSRange, range2: NSRange) -> NSRange { let intersection = NSIntersectionRange(range1, range2) return intersection }

Anonimo

13 apr 2020

extension NSRange { func my_intersection(with range: NSRange) -> NSRange? { guard range.lowerBound <= self.upperBound || self.lowerBound <= range.upperBound else { return nil } let start = max(self.lowerBound, range.lowerBound) let end = min(self.upperBound, range.upperBound) return NSRange(location: start, length: end - start) } }