Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

findNotContiguousOrRectangular.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use strict';
  2. const _ = require('lodash');
  3. /**
  4. *
  5. * @param {string[][]} areas
  6. * @param {string} name
  7. * @returns {boolean}
  8. */
  9. function isContiguousAndRectangular(areas, name) {
  10. const indicesByRow = areas.map((row) => {
  11. const indices = [];
  12. let idx = row.indexOf(name);
  13. while (idx !== -1) {
  14. indices.push(idx);
  15. idx = row.indexOf(name, idx + 1);
  16. }
  17. return indices;
  18. });
  19. for (let i = 0; i < indicesByRow.length; i++) {
  20. for (let j = i + 1; j < indicesByRow.length; j++) {
  21. if (indicesByRow[i].length === 0 || indicesByRow[j].length === 0) {
  22. continue;
  23. }
  24. if (!_.isEqual(indicesByRow[i], indicesByRow[j])) {
  25. return false;
  26. }
  27. }
  28. }
  29. return true;
  30. }
  31. /**
  32. *
  33. * @param {string[][]} areas
  34. * @returns {string[]}
  35. */
  36. function namedAreas(areas) {
  37. const names = new Set(_.flatten(areas));
  38. names.delete('.');
  39. return Array.from(names);
  40. }
  41. /**
  42. *
  43. * @param {string[][]} areas
  44. * @returns {string[]}
  45. */
  46. function findNotContiguousOrRectangular(areas) {
  47. return namedAreas(areas).filter((name) => !isContiguousAndRectangular(areas, name));
  48. }
  49. module.exports = findNotContiguousOrRectangular;