123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- export function useQuestionTools() {
- function getLetterByIndex(index) {
- let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- if (index < 0 || index > 26) {
- return '?';
- }
- return letters.charAt(index);
- }
- // 判断两个数组是否具有相同元素
- function haveSameElements(arr1, arr2) {
- // 如果两个数组的长度不同,它们不可能包含相同的元素
- if (arr1.length !== arr2.length) {
- return false;
- }
- // 对两个数组进行排序
- arr1.sort((a, b) => a - b);
- arr2.sort((a, b) => a - b);
- // 比较排序后的数组是否相同
- for (let i = 0; i < arr1.length; i++) {
- if (arr1[i] != arr2[i]) {
- return false;
- }
- }
- // 如果所有元素都相同,返回 true
- return true;
- }
- function checkDanxuanReply(item) {
- if (item.reply === 0 || item.reply === '0') {
- return true
- }
- if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
- return false;
- } else {
- return true;
- }
- }
- function checkDuoxuanReply(item) {
- if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
- return false;
- } else {
- for (const _item of item.reply) {
- if (_item === '') {
- return false;
- }
- }
- return true;
- }
- }
- function checkPanduanReply(item) {
- if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
- return false;
- } else {
- return true;
- }
- }
- function checkTiankongReply(item) {
- if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
- return false;
- } else {
- for (const _item of item.reply) {
- if (_item === '') {
- return false;
- }
- }
- return true;
- }
- }
- function checkJiandaReply(item) {
- if (!item.reply || item.reply === '' || item.reply === [] || item.reply.length === 0) {
- return false;
- } else {
- return true;
- }
- }
- function checkYueduReply(qa) {
- console.log('qa =>',qa)
- for (const iDanxuan of qa.danxuan) {
- if (!checkDanxuanReply(iDanxuan)) {
- return false;
- }
- }
- for (const iDuoxuan of qa.duoxuan) {
- if (!checkDuoxuanReply(iDuoxuan)) {
- return false;
- }
- }
- for (const iPanduan of qa.panduan) {
- if (!checkPanduanReply(iPanduan)) {
- return false;
- }
- }
- for (const iTiankong of qa.tiankong) {
- if (!checkTiankongReply(iTiankong)) {
- return false;
- }
- }
- for (const iJianda of qa.jianda) {
- if (!checkJiandaReply(iJianda)) {
- return false;
- }
- }
- return true;
- }
- return {
- getLetterByIndex,
- haveSameElements,
- checkDanxuanReply,
- checkDuoxuanReply,
- checkPanduanReply,
- checkTiankongReply,
- checkJiandaReply,
- checkYueduReply
- }
- }
|