Skip to content

Commit

Permalink
removed O(n) complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
hardik-pratap-singh committed Aug 15, 2024
1 parent ad3fd9f commit ec24b92
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions browser-extension/prototype/index3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ec24b92

Please sign in to comment.