useQuestionTools.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. export function useQuestionTools() {
  2. function getLetterByIndex(index) {
  3. let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  4. if (index < 0 || index > 26) {
  5. return '?';
  6. }
  7. return letters.charAt(index);
  8. }
  9. // 判断两个数组是否具有相同元素
  10. function haveSameElements(arr1, arr2) {
  11. // 如果两个数组的长度不同,它们不可能包含相同的元素
  12. if (arr1.length !== arr2.length) {
  13. return false;
  14. }
  15. // 对两个数组进行排序
  16. arr1.sort((a, b) => a - b);
  17. arr2.sort((a, b) => a - b);
  18. // 比较排序后的数组是否相同
  19. for (let i = 0; i < arr1.length; i++) {
  20. if (arr1[i] != arr2[i]) {
  21. return false;
  22. }
  23. }
  24. // 如果所有元素都相同,返回 true
  25. return true;
  26. }
  27. function checkDanxuanReply(item) {
  28. if (item.reply === 0 || item.reply === '0') {
  29. return true
  30. }
  31. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  32. return false;
  33. } else {
  34. return true;
  35. }
  36. }
  37. function checkDuoxuanReply(item) {
  38. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  39. return false;
  40. } else {
  41. for (const _item of item.reply) {
  42. if (_item === '') {
  43. return false;
  44. }
  45. }
  46. return true;
  47. }
  48. }
  49. function checkPanduanReply(item) {
  50. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  51. return false;
  52. } else {
  53. return true;
  54. }
  55. }
  56. function checkTiankongReply(item) {
  57. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  58. return false;
  59. } else {
  60. for (const _item of item.reply) {
  61. if (_item === '') {
  62. return false;
  63. }
  64. }
  65. return true;
  66. }
  67. }
  68. function checkJiandaReply(item) {
  69. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  70. return false;
  71. } else {
  72. return true;
  73. }
  74. }
  75. function checkYueduReply(qa) {
  76. console.log('qa =>',qa)
  77. for (const iDanxuan of qa.danxuan) {
  78. if (!checkDanxuanReply(iDanxuan)) {
  79. return false;
  80. }
  81. }
  82. for (const iDuoxuan of qa.duoxuan) {
  83. if (!checkDuoxuanReply(iDuoxuan)) {
  84. return false;
  85. }
  86. }
  87. for (const iPanduan of qa.panduan) {
  88. if (!checkPanduanReply(iPanduan)) {
  89. return false;
  90. }
  91. }
  92. for (const iTiankong of qa.tiankong) {
  93. if (!checkTiankongReply(iTiankong)) {
  94. return false;
  95. }
  96. }
  97. for (const iJianda of qa.jianda) {
  98. if (!checkJiandaReply(iJianda)) {
  99. return false;
  100. }
  101. }
  102. return true;
  103. }
  104. return {
  105. getLetterByIndex,
  106. haveSameElements,
  107. checkDanxuanReply,
  108. checkDuoxuanReply,
  109. checkPanduanReply,
  110. checkTiankongReply,
  111. checkJiandaReply,
  112. checkYueduReply
  113. }
  114. }