useQuestionTools.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. return {
  69. getLetterByIndex,
  70. haveSameElements,
  71. checkDanxuanReply,
  72. checkDuoxuanReply,
  73. checkPanduanReply,
  74. checkTiankongReply
  75. }
  76. }