useQuestionTools.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  29. return false;
  30. } else {
  31. return true;
  32. }
  33. }
  34. function checkDuoxuanReply(item) {
  35. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  36. return false;
  37. } else {
  38. for (const _item of item.reply) {
  39. if (_item === '') {
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45. }
  46. function checkPanduanReply(item) {
  47. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  48. return false;
  49. } else {
  50. return true;
  51. }
  52. }
  53. function checkTiankongReply(item) {
  54. if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
  55. return false;
  56. } else {
  57. for (const _item of item.reply) {
  58. if (_item === '') {
  59. return false;
  60. }
  61. }
  62. return true;
  63. }
  64. }
  65. return {
  66. getLetterByIndex,
  67. haveSameElements,
  68. checkDanxuanReply,
  69. checkDuoxuanReply,
  70. checkPanduanReply,
  71. checkTiankongReply
  72. }
  73. }