Improve distributedCopy
This commit is contained in:
parent
6844c8425a
commit
829eb0fe1f
|
@ -2,24 +2,21 @@
|
|||
* Retrieve a fixed number of elements from an array, evenly distributed but
|
||||
* 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.
|
||||
* @returns {Array}
|
||||
*/
|
||||
export function distributedCopy(items, take) {
|
||||
if (items.length < take) {
|
||||
return items
|
||||
}
|
||||
|
||||
const elements = [items[0]]
|
||||
const totalItems = items.length - 2
|
||||
const interval = Math.floor(totalItems / (take - 2))
|
||||
|
||||
for (let i = 1; i < take - 1; i++) {
|
||||
elements.push(items[i * interval])
|
||||
}
|
||||
|
||||
elements.push(items[items.length - 1])
|
||||
|
||||
return elements
|
||||
export function distributedCopy(originalArray, take) {
|
||||
if (originalArray.length <= take) return [...originalArray]
|
||||
|
||||
const newArray = [originalArray[0]]
|
||||
|
||||
const interval = (originalArray.length - 2) / (take - 2)
|
||||
|
||||
for (let i = 1; i < take - 1; i++)
|
||||
newArray.push(originalArray[Math.floor(interval * i)])
|
||||
|
||||
newArray.push(originalArray[originalArray.length - 1])
|
||||
|
||||
return newArray
|
||||
}
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
<br />
|
||||
</div>
|
||||
<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-model="filter"
|
||||
label="Filtro"
|
||||
|
@ -104,7 +107,7 @@ export default {
|
|||
notes
|
||||
updatedAt
|
||||
|
||||
stats(take: 60) {
|
||||
stats(take: 128) {
|
||||
id
|
||||
timestamp
|
||||
clients
|
||||
|
|
Loading…
Reference in New Issue
Block a user