mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
simplify filterAndSort() js function.
This commit is contained in:
@@ -119,30 +119,30 @@ function getPlatform() {
|
|||||||
function filterAndSort(children) {
|
function filterAndSort(children) {
|
||||||
const platform = getPlatform();
|
const platform = getPlatform();
|
||||||
|
|
||||||
const filteredElements = Array.from(children).filter((element) => {
|
const parent = children[0].parentNode;
|
||||||
const platformAttr = element.getAttribute('data-platform');
|
const elements = []
|
||||||
return platform === platformAttr || platformAttr === 'web' || platformAttr === 'native' || platformAttr === 'dummy';
|
for (let i = 0; i < children.length; i++) {
|
||||||
});
|
let element = children[i]
|
||||||
|
switch (element.getAttribute('data-platform')) {
|
||||||
Array.from(children).forEach((element) => {
|
case platform:
|
||||||
if (!filteredElements.includes(element)) {
|
case 'web':
|
||||||
element.remove();
|
case 'native':
|
||||||
|
case 'dummy':
|
||||||
|
elements.push(element)
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
const sortedElements = filteredElements.sort(
|
elements.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
parseInt(b.getAttribute('count')) - parseInt(a.getAttribute('count'))
|
parseInt(b.getAttribute('count')) - parseInt(a.getAttribute('count'))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Assuming you want to re-insert the sorted elements into their parent container
|
parent.innerHTML = ''
|
||||||
const parent = children[0].parentNode;
|
for (let i = 0; i < elements.length; i++) {
|
||||||
parent.innerHTML = ''; // Clear the parent container
|
parent.appendChild(elements[i]);
|
||||||
sortedElements.forEach((element) => {
|
};
|
||||||
parent.appendChild(element);
|
|
||||||
});
|
|
||||||
|
|
||||||
return sortedElements;
|
return elements;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user