test.forEach(item => item.tsNoTZ = new Date(item.dateAndTime.substring(0, 24)));
test.sort((a, b) => b.tsNoTZ - a.tsNoTZ);
И лучше только однажды пройти по массиву и добавить каждому объекту новое поле, по которому потом сортировать. let dataValues = {
id_key: 'A005012',
marginToEquityRate: 0,
leverage: 0,
maxDD: 0,
std: 0,
};
dataValues.std = 1;
alert(`В объекте dataValues свойство std равно ${dataValues.std}`);
Array.prototype.add_save = function( data ) {
this.push(data) //вставляем данные в массив
save_function(data) //вызов вашей функции сохранения данных
}
my_array.save_add(data)
export class Component {
constructor(
private _http: HttpClient,
private _elementRef: ElementRef
) {}
ngOnInit() {
const json = '{"--background-color": "black", "--text-color": "red"}';
this._http.get('host')._subscribe(_res => {
for (let [key, value] of Object.entries(
JSON.parse(json)
)) {
this._elementRef.nativeElement.style.setProperty(
key,
value
);
console.log({ key, value });
}
});
}
}
let trade_account: Trade_account | null | undefined; // явно указываем, что тип переменной - это undefined или Trade_account или null
<mat-slider (ngModelChange)="helpersService.slideValue1$.next(Number($event))"
[ngModel]="helpersService.slideValue1$.value"
min="0"
max="100"></mat-slider>
ngOnInit(): void {
this.helpersService.slideValue1$
.pipe(
takeUntil(this.destroy$),
tap(value => {
this.helpersService.slideValue2$.next(value);
)
)
.subscribe();
};
// или с методом
updateSliderValue(event: MatSliderChange){
this.helpersService.slideValue1$.next(Number(event));
}
const arrs = [ arr1, arr2 ];
), дальше есть варианты:const result = arrs[0].map((_, i) => arrs.flatMap(arr => arr[i]));
const result = arrs.reduce((acc, arr) => (
arr.forEach((n, i) => (acc[i] ??= []).push(...n)),
acc
), []);
const result = [];
for (const arr of arrs) {
for (const [ i, n ] of arr.entries()) {
if (!result[i]) {
result[i] = [];
}
for (const m of n) {
result[i][result[i].length] = m;
}
}
}
const chunkedAndTransposed = ([ headers, ...arr ], chunkSize) =>
arr.reduce((acc, n, i) => (
(i % chunkSize) || acc.push(headers.map(m => [ m ])),
n.forEach((m, j) => acc.at(-1)[j].push(m)),
acc
), []);
const result = chunkedAndTransposed(arr, 2);
const chunkedAndTransposed = (arr, chunkSize, defautlValue = null) =>
Array.from({ length: Math.ceil((arr.length - 1) / chunkSize) }, (_, iChunk) =>
Array.from({ length: arr[0].length }, (_, iCol) =>
Array.from({ length: chunkSize + 1 }, (_, iRow) =>
iRow ? arr[iChunk * chunkSize + iRow]?.[iCol] ?? defautlValue : arr[0][iCol]
)
)
);
const result = chunkedAndTransposed(arr, 5);
const map = {
n: "account_name",
d: "start_deposit",
c: "client_name",
b: "ib_account_number",
l: "leverage",
e: "description",
r: "rebalance_model",
m: "model_settings",
s: "selected_systems",
w: "target_weights",
}
let key = "ndcbler";
const hasSettings = this.newAccount.model_settings !== "{}";
const hasWeights = this.newAccount.target_weights !== "{}";
if (hasSettings && hasWeights) {
key += "swm";
} else if (hasSettings) {
key += "m";
} else if (hasWeights) {
key += "sw";
// } else { // что делаем, если ни того ни того нет?
// key = "";
}
this.objForPost = key.split("")
.map((key) => `-${key} ${this.newAccount[map[key]]}`)
.join(" ");
const с = `-n ${this.newAccount.account_name}`
+ ` -d ${this.newAccount.start_deposit}`
+ ` -c ${this.newAccount.client_name}`
+ ` -b ${this.newAccount.ib_account_number}`
+ ` -l ${this.newAccount.leverage}`
+ ` -e ${this.newAccount.description}`
+ ` -r ${this.newAccount.rebalance_model}`;
if (this.newAccount.model_settings !== "{}") {
this.objForPost = с
+ ` -m "${this.newAccount.model_settings}"`;
} else if (this.newAccount.target_weights !== "{}") {
this.objForPost = c
+ ` -s ${this.newAccount.selected_systems}`
+ ` -w "${this.newAccount.target_weights}"`;
} else if (this.newAccount.model_settings !== "{}"
&& this.newAccount.target_weights !== "{}"
) {
this.objForPost = с
+ ` -s ${this.newAccount.selected_systems}`
+ ` -w "${this.newAccount.target_weights}"`
+ ` -m "${this.newAccount.model_settings}"`;
}
let {
account_name,
start_deposit,
client_name,
ib_account_number,
leverage,
description,
rebalance_model,
model_settings,
selected_systems,
target_weights,
} = this.newAccount;
const с = `-n ${account_name}`
+ ` -d ${start_deposit}`
+ ` -c ${client_name}`
+ ` -b ${ib_account_number}`
+ ` -l ${leverage}`
+ ` -e ${description}`
+ ` -r ${rebalance_model}`;
if (model_settings !== "{}") {
this.objForPost = с + ` -m "${model_settings}"`;
} else if (target_weights !== "{}") {
this.objForPost = c + ` -s ${selected_systems} -w "${target_weights}"`;
} else if (model_settings !== "{}" && target_weights !== "{}") {
this.objForPost = с + ` -s ${selected_systems} -w "${target_weights}" -m "${model_settings}"`;
}