Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Map-range/Swift/map-range.swift
Normal file
12
Task/Map-range/Swift/map-range.swift
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import Foundation
|
||||
|
||||
func mapRanges(_ r1: ClosedRange<Double>, _ r2: ClosedRange<Double>, to: Double) -> Double {
|
||||
let num = (to - r1.lowerBound) * (r2.upperBound - r2.lowerBound)
|
||||
let denom = r1.upperBound - r1.lowerBound
|
||||
|
||||
return r2.lowerBound + num / denom
|
||||
}
|
||||
|
||||
for i in 0...10 {
|
||||
print(String(format: "%2d maps to %5.2f", i, mapRanges(0...10, -1...0, to: Double(i))))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue