8000 Make x variable explicit in closure · codee/swift-algorithm-club@40d0748 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40d0748

Browse files
committed
Make x variable explicit in closure
1 parent 1c09008 commit 40d0748

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Linear Regression/LinearRegression.playground/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func linearRegression(_ xs: [Double], _ ys: [Double]) -> ((Double) -> Double) {
4242
let sum2 = average(multiply(xs, xs)) - pow(average(xs), 2)
4343
let slope = sum1 / sum2
4444
let intercept = average(ys) - slope * average(xs)
45-
return { intercept + slope * $0 }
45+
return { x in intercept + slope * x }
4646
}
4747

4848
let result = linearRegression(carAge, carPrice)(4)

0 commit comments

Comments
 (0)
0