Created
March 6, 2023 19:11
-
-
Save jboursiquot/6a2a07f73baee0a5fb9a9483482cb004 to your computer and use it in GitHub Desktop.
Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math" | |
) | |
type Point struct { | |
Val float64 | |
Ts uint32 | |
} | |
func Fix(in []Point, from, to, interval uint32) []Point { | |
var res []Point | |
for i := from; i < to; i += interval { | |
v := (i / interval) * interval | |
if i%interval != 0 { | |
res = append(res, find(in, v+interval)) | |
continue | |
} | |
res = append(res, find(in, v)) | |
} | |
return res | |
} | |
func find(in []Point, ts uint32) Point { | |
for _, p := range in { | |
if p.Ts == ts { | |
return p | |
} | |
} | |
return Point{math.NaN(), ts} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment