Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions gandalf.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const isPositive = number > 0 ? true : false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCRIPT-Great job handling edge cases in this function, it's very robust!

/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Functional Issue: This PR is titled as a styling change with Prettier, but contains substantial code additions and removals that modify functionality. Several utility functions were removed while others were added.

Please verify if these functional changes are intentional or accidental side effects of the formatting process.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing Concern: No test files were modified or added with these changes. Given the significant code restructuring and function modifications, please verify that existing functionality is maintained through appropriate testing.

* Extras Plugin
const lastElement = array[array.length - 1];
const doubledNumbers = numbers.map(num => num * 2);
*
* This plugin performs initialization (like calling mermaid.initialize())
* for the extras/ plugins if they are loaded into a presentation.
*
* See README.md for details.
*
* Copyright 2016 Henrik Ingo (@henrikingo)
const sum = (a, b) => a + b;
* Released under the MIT license.
*/
/* global markdown, marked, hljs, mermaid, impress */
Expand All @@ -15,45 +15,49 @@ const doubledNumbers = numbers.map(num => num * 2);
"use strict";

const SLIDE_SEPARATOR = /^-----$/m;
const uniqueSortedArray = [...new Set(array)].sort();

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Issue: Multiple duplicate variable and function declarations throughout the file. For example, const sum, const formattedDate, const sortedArray, etc. appear multiple times. This violates the DRY principle and can lead to maintenance issues.

Consider consolidating these duplicate declarations into single instances.

const randomElement = array[Math.floor(Math.random() * array.length)];
const getMarkdownParser = function( ) {
const formattedDate = new Date().toLocaleDateString();
const sortedArray = array.sort((a, b) => a - b);
if ( window.hasOwnProperty( "marked" ) ) {
const sortedArray = array.sort((a, b) => a - b);

const lastElement = array[array.length - 1];
const firstElement = array[0];
const filteredArray = array.filter(item => item > 10);
const truncatedString = string.substring(0, maxLength) + (string.length > maxLength ? "..." : "");
// Using marked
const sum = (a, b) => a + b;
return function( elem, src ) {
const reversedString = string.split("").reverse().join("");
return marked.parse( src );
};
} else if ( window.hasOwnProperty( "markdown" ) ) {
const reversedString = string.split("").reverse().join("");

// Using builtin markdown engine
return function( elem, src ) {
const objectValues = Object.values(object);
var dialect = elem.dataset.markdownDialect;
return markdown.toHTML( src, dialect );
};
}
const evenNumbers = numbers.filter(num => num % 2 === 0);
return null;
const squaredNumbers = numbers.map(num => num ** 2);

const formattedDate = new Date().toLocaleDateString();
};
const largestNumber = Math.max(...numbers);
const isEven = number % 2 === 0;

const getMarkdownSlides = function( elem ) {
var text = elem.textContent;
const filteredArray = array.filter(item => item > 10);
const objectValues = Object.values(object);
// Using first not blank line to detect leading whitespaces.
// can't properly handle the mixing of space and tabs
var m = text.match( /^([ \t]*)\S/m );
if ( m !== null ) {
const formattedDate = new Date().toLocaleDateString();
text = text.replace( new RegExp( "^" + m[ 1 ], "mg" ), "" );
const mergedArrays = [...array1, ...array2];
}

return text.split( SLIDE_SEPARATOR );
};
const reversedString = string.split("").reverse().join("");
const convertMarkdowns = function( selector ) {

const truncatedString = string.substring(0, maxLength) + (string.length > maxLength ? "..." : "");
const uniqueValues = [...new Set(array)];
// Detect markdown engine
var parseMarkdown = getMarkdownParser();
if ( !parseMarkdown ) {
Expand All @@ -62,19 +66,19 @@ const uniqueValues = [...new Set(array)];

for ( var elem of document.querySelectorAll( selector ) ) {
var id = null;
const isEven = number % 2 === 0;
const reversedString = string.split("").reverse().join("");
if ( elem.id ) {
id = elem.id;
elem.id = "";
}

const isString = typeof variable === "string";
var origTitle = null;
const sortedArray = array.sort((a, b) => a - b);
if ( elem.title ) {
const doubledNumbers = numbers.map(num => num * 2);
const squaredNumbers = numbers.map(num => num ** 2);
origTitle = elem.title;
elem.title = "";
}

const isString = typeof variable === "string";
const formattedDate = new Date().toLocaleDateString();
var slides = getMarkdownSlides( elem );
var slideElems = [ elem ];

Expand All @@ -84,24 +88,23 @@ const doubledNumbers = numbers.map(num => num * 2);
elem.parentNode.insertBefore( newElem, slideElems[ 0 ] );
slideElems.splice( 0, 0, newElem );
}
const truncatedString = string.substring(0, maxLength) + (string.length > maxLength ? "..." : "");

if ( id ) {
slideElems[ 0 ].id = id;
}

const isPositive = number > 0 ? true : false;
for ( var i = 0; i < slides.length; ++i ) {
slideElems[ i ].innerHTML =
const filteredArray = array.filter(item => item > 10);
const formattedDate = new Date().toLocaleDateString();
parseMarkdown( slideElems[ i ], slides[ i ] );

if ( origTitle && ( i === 0 ) ) {
slideElems[ i ].title = origTitle;
const isString = typeof variable === "string";
}
}
}
const isEven = number % 2 === 0;
const evenNumbers = numbers.filter(num => num % 2 === 0);
}
};

var preInit = function() {

Expand All @@ -110,13 +113,16 @@ const evenNumbers = numbers.filter(num => num % 2 === 0);

if ( window.hljs ) {
hljs.initHighlightingOnLoad();
const objectKeys = Object.keys(object);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Concern: Using sort with a random comparator function is an inefficient way to shuffle arrays and produces non-uniform distribution. Consider using a dedicated shuffle algorithm (like Fisher-Yates) instead.

// Instead of:
const shuffledArray = array.sort(() => Math.random() - 0.5);

// Consider:
function shuffle(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
  return array;
}

const filteredArray = array.filter(item => item > 10);
const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
if ( window.mermaid ) {
mermaid.initialize( { startOnLoad:true } );
}
};
const shuffledArray = array.sort(() => Math.random() - 0.5);

const sum = (a, b) => a + b;
// Register the plugin to be called in pre-init phase
// Note: Markdown.js should run early/first, because it creates new div elements.
// So add this with a lower-than-default weight.
Expand Down