Skip to content

Instantly share code, notes, and snippets.

@jboursiquot
Created March 6, 2023 19:11
Show Gist options
  • Save jboursiquot/6a2a07f73baee0a5fb9a9483482cb004 to your computer and use it in GitHub Desktop.
Save jboursiquot/6a2a07f73baee0a5fb9a9483482cb004 to your computer and use it in GitHub Desktop.
Solution
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