2
0

arrayfunctions.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. function names(array) {
  20. var names = [];
  21. for (var i=0; i<array.length; i++) {
  22. names[i] = array[i].name;
  23. }
  24. return names;
  25. }
  26. function nameWithPath(fan) {
  27. return fan.name + " (" + fan.path + ")";
  28. }
  29. function namesWithPaths(array) {
  30. var namesWithPaths = [];
  31. for (var i=0; i<array.length; i++) {
  32. namesWithPaths[i] = nameWithPath(array[i]);
  33. }
  34. return namesWithPaths;
  35. }
  36. function labels(array) {
  37. var labels = [];
  38. for (var i=0; i<array.length; i++) {
  39. labels[i] = array[i].label;
  40. }
  41. return labels;
  42. }
  43. function labelsWithPaths(array) {
  44. var labelsWithPaths = [];
  45. for (var i=0; i<array.length; i++) {
  46. labelsWithPaths[i] = array[i].label + " (" + array[i].path + ")";
  47. }
  48. return labelsWithPaths;
  49. }
  50. function maxProperty(array, prop) {
  51. var max = 0;
  52. for (var i=0; i<array.length; i++) {
  53. max = Math.max(max, array[i][prop]);
  54. }
  55. return max;
  56. }
  57. function minProperty(array, prop) {
  58. var min = 0;
  59. for (var i=0; i<array.length; i++) {
  60. min = Math.min(min, array[i][prop]);
  61. }
  62. return min;
  63. }