25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

20 lines
531 B

  1. import zipWith from "lodash/zipWith";
  2. export const roundToNearestQuarter = (n: number): number => {
  3. return Math.round(n / 0.25) * 0.25;
  4. };
  5. export const distributeQuarters = (hours: number, parts: number): number[] => {
  6. if (!parts) return [];
  7. const numQuarters = hours * 4;
  8. const equalParts = Math.floor(numQuarters / parts);
  9. const remainders = Array(numQuarters % parts).fill(1);
  10. return zipWith(
  11. Array(parts).fill(equalParts),
  12. remainders,
  13. (a, b) => a + (b || 0),
  14. ).map((quarters) => quarters / 4);
  15. };