Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Credit for User:Meriton for developing the following code (first published here). function replaceIn(e) { if (e.nodeType == Node.TEXT_NODE) { e.nodeValue = e.nodeValue.replaceAll("a", "");...
#7: Post edited
Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- How this recursive treewalker works?
- As a side question which I grasp as important, can there be an even simpler and more direct version without the `else`?
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)).
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- How this recursive treewalker works?
- As a side question which I grasp as important, can there be an even simpler and more direct version without the `else`?
#5: Post edited
Treewalker with just an if, no else
- How this recursive treewalker works?
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
Can this be achieved without `else`?If we just want to run on all characters in the document, why not do that in a direct command without conditioning?
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- How this recursive treewalker works?
- As a side question which I grasp as important, can there be an even simpler and more direct version without the `else`?
#3: Post edited
Treewalker without an if-else conditioning
- Treewalker without just an if, no else
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
Why does an if-else pattern is needed here and can the code be rephrased without it?- If we just want to run on all characters in the document, why not do that in a direct command without conditioning?
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- Can this be achieved without `else`?
- If we just want to run on all characters in the document, why not do that in a direct command without conditioning?
#2: Post edited
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
Why does an if-else pattern is needed here and can the code be rephrased without it?
- Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)):
- ```javascript
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- Why does an if-else pattern is needed here and can the code be rephrased without it?
- If we just want to run on all characters in the document, why not do that in a direct command without conditioning?
#1: Initial revision
Treewalker without an if-else conditioning
Credit for [User:Meriton](https://software.codidact.com/users/53280) for developing the following code ([first published here](https://software.codidact.com/posts/286304/286317#answer-286317)): ```javascript function replaceIn(e) { if (e.nodeType == Node.TEXT_NODE) { e.nodeValue = e.nodeValue.replaceAll("a", ""); } else { for (const child of e.childNodes) { replaceIn(child); } } } replaceIn(document.body); ``` Why does an if-else pattern is needed here and can the code be rephrased without it?