Improve distributedCopy

This commit is contained in:
Douglas Barone 2022-06-22 11:46:18 +00:00
parent 6844c8425a
commit 829eb0fe1f
2 changed files with 15 additions and 15 deletions

View File

@ -2,24 +2,21 @@
* Retrieve a fixed number of elements from an array, evenly distributed but * Retrieve a fixed number of elements from an array, evenly distributed but
* always including the first and last elements. * always including the first and last elements.
* *
* @param {Array} items - The array to operate on. * @param {Array} originalArray - The array to operate on.
* @param {number} take - The number of elements to extract. * @param {number} take - The number of elements to extract.
* @returns {Array} * @returns {Array}
*/ */
export function distributedCopy(items, take) { export function distributedCopy(originalArray, take) {
if (items.length < take) { if (originalArray.length <= take) return [...originalArray]
return items
} const newArray = [originalArray[0]]
const elements = [items[0]] const interval = (originalArray.length - 2) / (take - 2)
const totalItems = items.length - 2
const interval = Math.floor(totalItems / (take - 2)) for (let i = 1; i < take - 1; i++)
newArray.push(originalArray[Math.floor(interval * i)])
for (let i = 1; i < take - 1; i++) {
elements.push(items[i * interval]) newArray.push(originalArray[originalArray.length - 1])
}
return newArray
elements.push(items[items.length - 1])
return elements
} }

View File

@ -22,7 +22,10 @@
<br /> <br />
</div> </div>
<v-spacer /> <v-spacer />
<v-chip class="mr-2" outlined>
<v-icon left>mdi-account-group</v-icon>
{{ accessPoint.clients }} clientes conectados
</v-chip>
<v-text-field <v-text-field
v-model="filter" v-model="filter"
label="Filtro" label="Filtro"
@ -104,7 +107,7 @@ export default {
notes notes
updatedAt updatedAt
stats(take: 60) { stats(take: 128) {
id id
timestamp timestamp
clients clients