forked from DebaucheryLibrarian/traxxx
14 lines
523 B
JavaScript
14 lines
523 B
JavaScript
'use strict';
|
|
|
|
// pick {photoLimit} photos evenly distributed photos from a set with {photoTotal} photos, return array of indexes starting at 1
|
|
function pluckPhotos(photoTotal, photoLimit) {
|
|
const plucked = [1]
|
|
.concat(
|
|
Array.from({ length: photoLimit - 1 }, (value, index) => Math.round((index + 1) * (photoTotal / (photoLimit - 1)))),
|
|
);
|
|
|
|
return Array.from(new Set(plucked)); // remove duplicates, may happen when photo total and photo limit are close
|
|
}
|
|
|
|
module.exports = pluckPhotos;
|