You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * The method will increase the given number by 1. If the given counter is equal
  3. * or greater to {@link Number.MAX_SAFE_INTEGER} then it will be rolled back to
  4. * 1.
  5. * @param {number} number - An integer counter value to be incremented.
  6. * @return {number} the next counter value increased by 1 (see the description
  7. * above for exception).
  8. */
  9. export function safeCounterIncrement(number) {
  10. let nextValue = number;
  11. if (number >= Number.MAX_SAFE_INTEGER) {
  12. nextValue = 0;
  13. }
  14. return nextValue + 1;
  15. }
  16. /**
  17. * Calculates the average value of am Array of numbers.
  18. *
  19. * @param {Float32Array} valueArray - Array of numbers.
  20. * @returns {number} - Number array average.
  21. */
  22. export function calculateAverage(valueArray) {
  23. return valueArray.length > 0 ? valueArray.reduce((a, b) => a + b) / valueArray.length : 0;
  24. }
  25. /**
  26. * Returns only the positive values from an array of numbers.
  27. *
  28. * @param {Float32Array} valueArray - Array of vad scores.
  29. * @returns {Array} - Array of positive numbers.
  30. */
  31. export function filterPositiveValues(valueArray) {
  32. return valueArray.filter(value => value >= 0);
  33. }