Skip to content
Snippets Groups Projects
Commit 9cf7a632 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Recorded work from Wednesday.

parent 5e683840
No related branches found
No related tags found
No related merge requests found
export const DITTO = 'DITTO';
export function countTruesWithDittos(entries) {
return 0; // TODO
let lastBoolean = undefined;
let count = 0;
for (const entry of entries) {
if (entry !== DITTO) {
lastBoolean = entry;
}
if (lastBoolean === true) {
++count;
}
}
return count;
}
class MonoidElement {
constructor(/* TODO */) {
// TODO
constructor(lastBoolean, count, leadingDittoCount) {
this.lastBoolean = lastBoolean;
this.count = count;
this.leadingDittoCount = leadingDittoCount;
}
}
export const IDENTITY_ELEMENT = new MonoidElement(/* TODO */);
export const IDENTITY_ELEMENT = new MonoidElement(undefined, 0, 0);
export function encodeAsMonoidElement(entry) {
return new MonoidElement(
/* TODO */
entry === DITTO ? undefined : entry,
entry === true ? 1 : 0,
entry === DITTO ? 1 : 0,
);
}
export function combineMonoidElements(left, right) {
return new MonoidElement(
/* TODO */
right.lastBoolean === undefined ? left.lastBoolean : right.lastBoolean,
left.count + right.count + (left.lastBoolean === true ? right.leadingDittoCount : 0),
left.leadingDittoCount + (left.lastBoolean === undefined ? right.leadingDittoCount : 0),
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment