type Returns<T extends readonly Function[]> = {
-readonly [K in keyof T]: T[K] extends (...args: any[]) => PromiseLike<infer R> ? R : never;
};
type Arguments<T extends readonly Function[]> = {
[K in keyof T]?: T[K] extends (args: infer R, ...a: any[]) => any ? R : never;
};
function fetchAll<T extends readonly Function[]>(functions: readonly [...T], data?: Arguments<T>): Promise<Returns<T>> {
return Promise.all(
functions.map((func, index) => func(data?.[index]))
) as Promise<Returns<T>>;
}
const x = fetchAll([
(a:66) => Promise.resolve(42),
(f:string) => Promise.resolve('hello'),
() => Promise.resolve(true),
], [66, '1ff']);
const arr = [
(a:66) => Promise.resolve(42),
(f:string) => Promise.resolve('hello'),
() => Promise.resolve(true),
] as const;
const x = fetchAll(arr, [66, '1ff']);
const count = (arr) => arr.reduce((acc, num) => acc + num, 0);
com = con.CreateCommand();
var addMin_TB_Text = "10,77777";
var min = float.Parse(addMin_TB_Text);
var addMax_TB_Text = "20,77777";
var max = float.Parse(addMax_TB_Text);
var addCena_TB_Text = "33,3";
var cena = float.Parse(addCena_TB_Text);
var tonn = addMin_TB_Text + " - " + addMax_TB_Text;
com.CommandText = @"INSERT INTO t_stoimost (mintonn, maxtonn, tonn, cenakm)
VALUES ( @mintonn, @maxtonn, @tonn, @cenakm )";
com.Parameters.AddWithValue("@mintonn", min);
com.Parameters.AddWithValue("@maxtonn", max);
com.Parameters.AddWithValue("@tonn", tonn);
com.Parameters.AddWithValue("@cenakm", cena);
com.ExecuteNonQuery();
con.Close();
class Program
{
private static readonly Range[] ExistedRanges = {
new Range(0, 2),
new Range(5.01f, 7),
new Range(7.01f, 9)
};
public static bool IsValidRange(Range range)
{
return !ExistedRanges.Any(o => o.IsCross(range));
}
static void Main()
{
Console.WriteLine(IsValidRange(new Range(2.01f, 5)));
Console.WriteLine(IsValidRange(new Range(11, 13)));
Console.WriteLine(IsValidRange(new Range(1, 3)));
Console.WriteLine(IsValidRange(new Range(3, 10)));
Console.ReadKey();
}
}
public struct Range
{
public readonly float Start;
public readonly float End;
public Range(float start, float end)
{
Start = start;
End = end;
}
public bool IsCross(Range other)
{
return Math.Min(Math.Max(Start, End), Math.Max(other.Start, other.End)) >=
Math.Max(Math.Min(Start, End), Math.Min(other.Start, other.End));
}
}