数値リストdataの要素中で、値がもっともtargetに近い要素のインデックスを得る。
var diff = data.Select((x, index) => {
var diffX = Math.Abs(x - target);
return new { index, diffX };
});
var targetIndex = diff.OrderBy(d => d.diffX).First().index;
Go to list of users who liked
More than 5 years have passed since last update.
数値リストdataの要素中で、値がもっともtargetに近い要素のインデックスを得る。
var diff = data.Select((x, index) => {
var diffX = Math.Abs(x - target);
return new { index, diffX };
});
var targetIndex = diff.OrderBy(d => d.diffX).First().index;
Register as a new user and use Qiita more conveniently
Go to list of users who liked