Quiz 8: Implementing a triple
Question 1
Shows
true?JavaScript
const s1 = x => y => z => x; // select 1st argument
const s2 = x => y => z => y; // select 2nd argument
const s3 = x => y => z => z; // select 3rd argument
const triple = x => y => z => f => f(x)(y)(z);
const a = t => t(s1);
const b = t => t(s2);
const c = t => t(s3);
const oneTwoThree = triple(1)(2)(3);
document.writeln(a(oneTwoThree) === 1);Question 2
Shows
true?JavaScript
const s1 = x => y => z => x; // select 1st argument
const s2 = x => y => z => y; // select 2nd argument
const s3 = x => y => z => z; // select 3rd argument
const triple = x => y => z => f => f(x)(y)(z);
const a = t => t(s1);
const b = t => t(s2);
const c = t => t(s3);
const oneTwoThree = triple(1);
document.writeln(a(oneTwoThree) === 1);Question 3
Shows
true?JavaScript
const s1 = x => y => z => x; // select 1st argument
const s2 = x => y => z => y; // select 2nd argument
const s3 = x => y => z => z; // select 3rd argument
const triple = x => y => z => f => f(x)(y)(z);
const a = t => t(s1);
const b = t => t(s2);
const c = t => t(s3);
const person = triple;
const firstname = a;
const lastname = b;
const age = c;
const bran = person('Brendan')('Eich')(50);
document.writeln(firstname(bran) === 'Brendan');Question 4
Shows
true?JavaScript
const s1 = x => y => z => x; // select 1st argument
const s2 = x => y => z => y; // select 2nd argument
const s3 = x => y => z => z; // select 3rd argument
const triple = x => y => z => f => f(x)(y)(z);
const a = t => t(s1);
const b = t => t(s2);
const c = t => t(s3);
const person = triple;
const firstname = a;
const lastname = b;
const age = c;
const bran = person('Brendan');
const raven = bran('Stark')(16);
const eich = bran('Eich')(50);
document.writeln(firstname(bran) === 'Brendan');Question 5
Shows
true?JavaScript
const s1 = x => y => z => x; // select 1st argument
const s2 = x => y => z => y; // select 2nd argument
const s3 = x => y => z => z; // select 3rd argument
const triple = x => y => z => f => f(x)(y)(z);
const a = t => t(s1);
const b = t => t(s2);
const c = t => t(s3);
const person = triple;
const firstname = a;
const lastname = b;
const age = c;
const bran = person('Brendan');
const raven = bran('Stark')(16);
const eich = bran('Eich')(50);
document.writeln(age(raven) === 16);