it('#isList', () => { const numbers = l(3, 4, 5); expect(isList(numbers)).toBe(true); expect(isList(l())).toBe(true); expect(isList(5)).toBe(false); expect(!isList(pairs.cons(3, pairs.cons(3, 2)))).toBe(true); });
const run = (player1, player2, cards, customRandom) => { const iter = (health1, name1, health2, name2, order, log) => { if (health1 <= 0) { return consList(cons(car(head(log)), `${name1} был убит`), log); } const card = customRandom(cards); const cardName = getName(card); const points = damage(card, health2); const newHealth = health2 - points; const message = `Игрок '${name1}' применил '${cardName}' против '${name2}' и нанес урон '${damage}'`; let stats; if (order === 1) { stats = cons(cons(health1, newHealth), message); } else if (order === 2) { stats = cons(cons(newHealth, health1), message); } const newLog = consList(stats, log); return iter(newHealth, name2, health1, name1, order === 1 ? 2 : 1, newLog); }; const startHealth = 10; const logItem = cons(cons(startHealth, startHealth), 'Начинаем бой'); return reverse(iter(startHealth, player1, startHealth, player2, 1, l(logItem))); };
const generateQuestion = () => { const firstNum = generateRandomNum(minNumber, maxNumber); const secondNum = generateRandomNum(minNumber, maxNumber); const question = `${firstNum} ${secondNum}`; const answer = String(gcd(firstNum, secondNum)); return cons(question, answer); };
const iter = (health1, name1, health2, name2, order, log) => { if (health1 <= 0) { return consList(cons(car(head(log)), `${name1} был убит`), log); } const card = customRandom(cards); const cardName = getName(card); const points = damage(card, health2); const newHealth = health2 - points; const message = `Игрок '${name1}' применил '${cardName}' против '${name2}' и нанес урон '${damage}'`; let stats; if (order === 1) { stats = cons(cons(health1, newHealth), message); } else if (order === 2) { stats = cons(cons(newHealth, health1), message); } const newLog = consList(stats, log); return iter(newHealth, name2, health1, name1, order === 1 ? 2 : 1, newLog); };
const generateQuestion = () => { const firstNum = generateRandomNum(minNumber, maxNumber); const secondNum = generateRandomNum(minNumber, maxNumber); const randomSign = generateRandomSign(); const question = `${firstNum} ${randomSign} ${secondNum}`; let answer; switch (randomSign) { case '+': answer = firstNum + secondNum; break; case '-': answer = firstNum - secondNum; break; case '*': answer = firstNum * secondNum; break; default: console.log('sign not defined'); break; } return cons(question, String(answer)); };
it('#checkList', () => { const pair = pairs.cons(3, pairs.cons(3, 2)); expect(() => checkList(pair)).toThrowError('pair: (3, (3, 2))'); });
it('#toString2', () => { const list = l(3, l(4, 5), l(10, l(3)), 5, 5); expect(toString(list)).toBe('(3, (4, 5), (10, (3)), 5, 5)'); const list2 = l(3, pairs.cons(4, 5), pairs.cons(10, 3), 5, 5); expect(toString(list2)).toBe('(3, pair: (4, 5), pair: (10, 3), 5, 5)'); });
const gameBalance = () => { const question = generateRandomNumber(minNumber, maxNumber); const correctAnswer = getBalancedNumber(question); const pairOfQuestionAndAnswer = cons(question, correctAnswer); return pairOfQuestionAndAnswer; };
export const attach = (tag, data) => cons(tag, data);
export const makePoint = (x: Number, y: Number): Point => cons(x, y);
const generateQuestion = () => { const question = String(generateRandomNum(minNumber, maxNumber)); const answer = checkIsPrime(question); return cons(question, answer); };
export const cons = (element: any, list: List) => { checkList(list); return pairs.cons(element, list); };
const gameEven = () => { const question = generateRandomNumber(minNumber, maxNumber); const correctAnswer = isEven(question) ? 'yes' : 'no'; const pairOfQuestionAndAnswer = cons(question, correctAnswer); return pairOfQuestionAndAnswer; };
export const node = (tag, mix = data.l()) => cons(tag, mix);
const generateQuestion = () => { const question = generateRandomNum(minNumber, maxNumber); const answer = checkIsEven(question); return cons(question, answer); };