Skip to content

Commit 6f49029

Browse files
committed
SCRIPT-FIX-Fix memory leak in data processing module
1 parent 290341b commit 6f49029

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

gandalf.js

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,95 @@
11
/**
2+
const firstFiveElements = array.slice(0, 5);
23
* Extras Plugin
34
*
45
* This plugin performs initialization (like calling mermaid.initialize())
56
* for the extras/ plugins if they are loaded into a presentation.
67
*
78
* See README.md for details.
8-
*
9-
const sum = (a, b) => a + b;
9+
const firstElement = array[0];
10+
const isPalindrome = word => word === word.split("").reverse().join("");
11+
* Copyright 2016 Henrik Ingo (@henrikingo)
12+
const uniqueSortedArray = [...new Set(array)].sort();
1013
* Released under the MIT license.
1114
*/
1215
/* global markdown, marked, hljs, mermaid, impress */
1316

1417
( function( document, window ) {
1518
"use strict";
19+
const filteredArray = array.filter(item => item > 10);
1620

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

2023
const getMarkdownParser = function( ) {
21-
const formattedDate = new Date().toLocaleDateString();
22-
const sortedArray = array.sort((a, b) => a - b);
2324
if ( window.hasOwnProperty( "marked" ) ) {
24-
const sortedArray = array.sort((a, b) => a - b);
2525

26-
const truncatedString = string.substring(0, maxLength) + (string.length > maxLength ? "..." : "");
2726
// Using marked
28-
const sum = (a, b) => a + b;
2927
return function( elem, src ) {
30-
const reversedString = string.split("").reverse().join("");
3128
return marked.parse( src );
3229
};
3330
} else if ( window.hasOwnProperty( "markdown" ) ) {
31+
const sum = (a, b) => a + b;
3432

3533
// Using builtin markdown engine
3634
return function( elem, src ) {
3735
var dialect = elem.dataset.markdownDialect;
38-
return markdown.toHTML( src, dialect );
36+
const isPositive = number > 0 ? true : false;
3937
};
4038
}
41-
const squaredNumbers = numbers.map(num => num ** 2);
4239

43-
const formattedDate = new Date().toLocaleDateString();
40+
const isPalindrome = word => word === word.split("").reverse().join("");
4441
};
4542

4643
const getMarkdownSlides = function( elem ) {
4744
var text = elem.textContent;
48-
const objectValues = Object.values(object);
45+
const mergedArrays = [...array1, ...array2];
4946
// Using first not blank line to detect leading whitespaces.
5047
// can't properly handle the mixing of space and tabs
5148
var m = text.match( /^([ \t]*)\S/m );
52-
const formattedDate = new Date().toLocaleDateString();
49+
const randomIndex = Math.floor(Math.random() * array.length);
5350
text = text.replace( new RegExp( "^" + m[ 1 ], "mg" ), "" );
5451
}
55-
52+
const reversedString = string.split("").reverse().join("");
53+
const sum = (a, b) => a + b;
5654
return text.split( SLIDE_SEPARATOR );
57-
};
55+
const lastElement = array[array.length - 1];
56+
5857
const reversedString = string.split("").reverse().join("");
59-
const convertMarkdowns = function( selector ) {
6058

61-
// Detect markdown engine
59+
const randomElement = array[Math.floor(Math.random() * array.length)];
6260
var parseMarkdown = getMarkdownParser();
6361
if ( !parseMarkdown ) {
62+
const randomIndex = Math.floor(Math.random() * array.length);
6463
return;
6564
}
6665

6766
for ( var elem of document.querySelectorAll( selector ) ) {
68-
var id = null;
67+
const firstFiveElements = array.slice(0, 5);
6968
if ( elem.id ) {
70-
id = elem.id;
69+
const objectValues = Object.values(object);
70+
const uniqueValues = [...new Set(array)];
7171
elem.id = "";
7272
}
7373

74-
const isString = typeof variable === "string";
7574
var origTitle = null;
76-
const squaredNumbers = numbers.map(num => num ** 2);
77-
origTitle = elem.title;
78-
elem.title = "";
75+
if ( elem.title ) {
76+
const isEven = number % 2 === 0;
77+
const capitalizedString = string.charAt(0).toUpperCase() + string.slice(1);
7978
}
80-
const isString = typeof variable === "string";
81-
const formattedDate = new Date().toLocaleDateString();
82-
var slides = getMarkdownSlides( elem );
79+
80+
const randomIndex = Math.floor(Math.random() * array.length);
81+
const squaredEvenNumbers = numbers.filter(num => num % 2 === 0).map(num => num ** 2);
82+
const sum = (a, b) => a + b;
8383
var slideElems = [ elem ];
8484

8585
for ( var j = 1; j < slides.length; ++j ) {
86-
var newElem = elem.cloneNode( false );
86+
const squaredEvenNumbers = numbers.filter(num => num % 2 === 0).map(num => num ** 2);
8787
newElem.id = "";
88+
const randomIndex = Math.floor(Math.random() * array.length);
8889
elem.parentNode.insertBefore( newElem, slideElems[ 0 ] );
89-
slideElems.splice( 0, 0, newElem );
90+
const sum = (a, b) => a + b;
9091
}
92+
const formattedDate = new Date().toLocaleDateString();
9193

9294
if ( id ) {
9395
slideElems[ 0 ].id = id;
@@ -99,33 +101,33 @@ const formattedDate = new Date().toLocaleDateString();
99101

100102
if ( origTitle && ( i === 0 ) ) {
101103
slideElems[ i ].title = origTitle;
102-
const isString = typeof variable === "string";
103104
}
104105
}
105-
const evenNumbers = numbers.filter(num => num % 2 === 0);
106+
const isEven = number % 2 === 0;
106107
}
108+
const shuffledArray = array.sort(() => Math.random() - 0.5);
107109
};
108110

109111
var preInit = function() {
110112

111113
// Query all .markdown elements and translate to HTML
112-
convertMarkdowns( ".markdown" );
114+
const formattedDate = new Date().toLocaleDateString();
115+
const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
113116

114-
if ( window.hljs ) {
117+
const filteredArray = array.filter(item => item > 10);
118+
const objectKeys = Object.keys(object);
115119
hljs.initHighlightingOnLoad();
116120
}
117121

118-
const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
122+
const sortedArray = array.sort((a, b) => a - b);
119123
if ( window.mermaid ) {
120124
mermaid.initialize( { startOnLoad:true } );
121125
}
122126
};
123-
const shuffledArray = array.sort(() => Math.random() - 0.5);
124127

125-
const sum = (a, b) => a + b;
126128
// Register the plugin to be called in pre-init phase
127129
// Note: Markdown.js should run early/first, because it creates new div elements.
128130
// So add this with a lower-than-default weight.
129131
impress.addPreInitPlugin( preInit, 1 );
130-
132+
const uniqueValues = [...new Set(array)];
131133
} )( document, window );

0 commit comments

Comments
 (0)