From ec24b92eec050b92fed41cd4a6e2cdc8c113093a Mon Sep 17 00:00:00 2001 From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in> Date: Thu, 15 Aug 2024 13:31:40 +0530 Subject: [PATCH] removed O(n) complexity --- browser-extension/prototype/index3.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/browser-extension/prototype/index3.js b/browser-extension/prototype/index3.js index c4273773..42f5dab7 100644 --- a/browser-extension/prototype/index3.js +++ b/browser-extension/prototype/index3.js @@ -76,11 +76,16 @@ function locateSlur(uliStore, targetWords) { uliStore[i].slurs = slurs; - parentNode.childNodes.forEach((node) => { - if (node === textnode) { - parentNode.replaceChild(tempParent, node) - } - }); + //Additional O(N) complexity + // parentNode.childNodes.forEach((node) => { + // if (node === textnode) { + // parentNode.replaceChild(tempParent, node) + // } + // }); + + //O(1) complexity + parentNode.replaceChild(tempParent, node) + } return uliStore; //This will return the final uliStore (after appending slurs) } @@ -146,8 +151,7 @@ function addMetaData(targetWords) { }) } -// let imgSrc = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png" -// let imgAlt = "slur word desc" + let targetWords = ["stupid", "crazy", "Crazy", "mad" , "Mad" , "MAD"] let uliStore = [] getAllTextNodes(document.body, uliStore)