UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

44 lines 2.24 kB
/** * thinArray will take an array of elements and * return 'relatively' evenly spaced elements at for total of 'count' items. * NOTE that the spacing may not seem very even when the length is smaller * * example: array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], count === 2: * return: [ 0, 9 ] * if count === 3: return: [0,4,9] * if count === 4: return: [0,2,5,9] * * FRINGE CASE: * Added pushEven for when 1 < ratio < 2 where it would return [0] instead of every other element. As an example if length === 99 and count === 51, it would return [0] but of count were 50 it would give every other item. So now, if the ratio of length / count < 2, it will just return the first, every other one and the last. So if you had an array of length 99 and asked for 98 back, it would only give you an array with 50 items... 0,2,4,6,8,10..., 98 so every other item. This means in this case, you could get far less items back than the count, but then the logic would not have to decide which ones to skip. * * * @param array * @param count * @returns */ export declare function thinArray(array: any[], count?: number): any[]; /** * getSpreadIndexes will take the length (of an array) and * return evenly spaced zero-based indexes for total of 'count' indexes. * * example: array = [ A, B, C, D, E, F, G, H, I, J, ] ( length === 10 ), count === 2: * return: [ 0, 9 ] =>>> if you map these indexes, the result would be: [ A, J ] * if count === 3: return: [0,4,9] =>>> if you map these indexes, the result would be: [ A, E, J ] * if count === 4: return: [0,2,5,9] =>>> if you map these indexes, the result would be: [ A, C, F, J ] * * NOTE FRINGE CASE MENTIONED IN thinArray function where the 1 < ( length / count ) < 2 * You may not get the total count of items back in that case. but every other item instead. * * @param array * @param count * @returns */ export declare function getSpreadIndexes(arrayLength: number, count: number): number[]; /** * The following commented code is what I tested in code pen for reference and testing if needed */ //# sourceMappingURL=thinOutArray.d.ts.map