mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 01:28:07 +00:00
access array last element without at
This commit is contained in:
parent
aedff736b5
commit
70595ae790
@ -59,9 +59,9 @@ class RelationsOrderer {
|
|||||||
r.order = 0.5;
|
r.order = 0.5;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
} else {
|
} else {
|
||||||
const lastRelation = this.arr.at(-1);
|
const lastRelation = this.arr[this.arr.length - 1];
|
||||||
// TODO: Use a big number instead of lastRelation.order
|
// TODO: Use a big number instead of lastRelation.order
|
||||||
if (lastRelation.init) r.order = lastRelation.order + 0.5;
|
if (lastRelation?.init) r.order = lastRelation.order + 0.5;
|
||||||
else r.order = lastRelation.order;
|
else r.order = lastRelation.order;
|
||||||
idx = this.arr.length;
|
idx = this.arr.length;
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ class RelationsOrderer {
|
|||||||
return _(this.arr)
|
return _(this.arr)
|
||||||
.groupBy('order')
|
.groupBy('order')
|
||||||
.reduce((acc, relations) => {
|
.reduce((acc, relations) => {
|
||||||
if (relations.at(0).init) return acc;
|
if (relations[0]?.init) return acc;
|
||||||
relations.forEach((relation, idx) => {
|
relations.forEach((relation, idx) => {
|
||||||
acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
|
acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user