Skip to content

Commit

Permalink
Use native for loop to avoid nested check
Browse files Browse the repository at this point in the history
  • Loading branch information
FAMarfuaty authored and leonidasmi committed Oct 30, 2024
1 parent dcd153e commit 3e4eb95
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ export default class ListAssessment extends Assessment {
*/
findList( paper ) {
const foundLists = paper.getTree().findAll( node => node.name === "ul" || node.name === "ol" );
/*
This is a helper function to check if a list is not empty.
A list is not empty if it has at least one <li> child with text.
*/
const isListNotEmpty = list => list.childNodes.some( child => child.name === "li" && child.childNodes.length );

return foundLists.some( isListNotEmpty );
for ( const list of foundLists ) {
for ( const child of list.childNodes ) {
// A list is not empty if it has at least one <li> child with text.
if ( child.name === "li" && child.childNodes.some( node => node.name === "p" ) ) {
return true;
}
}
}

return false;
}

/**
Expand Down

0 comments on commit 3e4eb95

Please sign in to comment.