Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Monoid Implementation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSCE 310
Monoid Implementation
Commits
9cf7a632
Commit
9cf7a632
authored
1 year ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Recorded work from Wednesday.
parent
5e683840
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
monoid-implementation/src/ditto.js
+22
-6
22 additions, 6 deletions
monoid-implementation/src/ditto.js
with
22 additions
and
6 deletions
monoid-implementation/src/ditto.js
+
22
−
6
View file @
9cf7a632
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
),
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment