Ad
Code
Diff
  • func gradeCalc(_ score: Int) -> String {
      (0...100~=score) ? String(Array("FFFFFFDCBAA")[score/10]) : "Not a grade" 
    }
    
    
    
    • func gradeCalc(_ score: Int) -> String {
    • (0...100~=score) ? ["F","F","F","F","F","F","D","C","B","A","A"][score / 10] : "Not a grade"
    • (0...100~=score) ? String(Array("FFFFFFDCBAA")[score/10]) : "Not a grade"
    • }
Code
Diff
  • func gradeCalc(_ score: Int) -> String {
        (score < 0 || score > 100) ? "Not a grade" : String(Array("FFFFFFDCBAA")[score / 10]);
    }
    • func gradeCalc(_ score: Int) -> String {
    • (score < 0 || score > 100) ? "Not a grade" : ["F","F","F","F","F","F","D","C","B","A","A"][score / 10];
    • (score < 0 || score > 100) ? "Not a grade" : String(Array("FFFFFFDCBAA")[score / 10]);
    • }
Code
Diff
  • extension String {
        func insert(_ value: String, interval: Int) -> String {
            guard interval > 0 && interval < count else { return self }
            let chars = Array(self)
            var result = ""
            var i = 0
            while i+interval<count {
                result.append(String(chars[i..<min(count,i+interval)])+value)
                i += interval
            }
            result.append(String(chars[i..<min(count,i+interval)]))
            return result 
        }
    }
    
    • extension String {
    • func insert(_ value: String, interval: Int) -> String {
    • guard interval > 0 && interval < count else { return self }
    • let chars = Array(self)
    • var result = ""
    • var i = 0
    • while i+interval<count {
    • result.append(String(chars[i..<min(count,i+interval)]))
    • result.append(value)
    • result.append(String(chars[i..<min(count,i+interval)])+value)
    • i += interval
    • }
    • result.append(String(chars[i..<min(count,i+interval)]))
    • return result
    • }
    • }
Code
Diff
  • extension String {
        func insert(_ value: String, interval: Int) -> String {
            guard interval > 0 && interval < count else { return self }
            let chars = Array(self)
            var result = ""
            var i = 0
            while i+interval<count {
                result.append(String(chars[i..<min(count,i+interval)]))
                result.append(value)
                i += interval
            }
            result.append(String(chars[i..<min(count,i+interval)]))
            return result 
        }
    }
    
    • extension String {
    • func insert(_ value: String, interval: Int) -> String {
    • guard interval > 0 && interval < count else { return self }
    • let chars = Array(self)
    • var result = ""
    • for (index, char) in self.enumerated() {
    • result += String(char)
    • if (index + 1) % interval == 0 && index + 1 != count {
    • result += value
    • }
    • var i = 0
    • while i+interval<count {
    • result.append(String(chars[i..<min(count,i+interval)]))
    • result.append(value)
    • i += interval
    • }
    • return result
    • result.append(String(chars[i..<min(count,i+interval)]))
    • return result
    • }
    • }