Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

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.

Activity for hkotsubo‭

Type On... Excerpt Status Date
Comment Post #286349 As explained [here](https://software.codidact.com/posts/286333), there are different types of nodes. And this code traverses through all document's nodes, but the replace only makes sense in text nodes ([here](https://software.codidact.com/posts/286304/286334#answer-286334) there's an explanation of ...
(more)
over 2 years ago
Edit Post #286346 Post edited:
over 2 years ago
Edit Post #286345 Post edited:
added relevant tag
over 2 years ago
Suggested Edit Post #286345 Suggested edit:
added relevant tag
(more)
helpful over 2 years ago
Edit Post #286347 Initial revision over 2 years ago
Answer A: Recursion without a procedure ("function") in JavaScript
Yes, it's possible. In a more general way, every recursive algorithm can be converted to an iterative one (and vice-versa). You just need to use a stack). Internally, a recursive function will use a stack to "remember" its "level" (because each recursive call is like entering a new "level" - ju...
(more)
over 2 years ago
Edit Post #286346 Post edited:
over 2 years ago
Edit Post #286346 Initial revision over 2 years ago
Answer A: Does a for...of loop must contain a variable without assignment sign, and why?
> Does a `for...of` loop must contain a variable without assignment sign (`=`) Yes. > and why? Because that's the syntax defined by the language specification. The people who defined it decided to do it that way. Unless those people answer here (or we find a discussion about it somewhere,...
(more)
over 2 years ago
Suggested Edit Post #286335 Suggested edit:
formatting, added tag
(more)
declined over 2 years ago
Edit Post #286337 Initial revision over 2 years ago
Answer A: What are the types of DOM nodes?
> any DOM "tree" node is actually a "branch" Not exactly. Document Object Model and Nodes According to the MDN documentation, the DOM (Document Object Model) is "the data representation of the objects that comprise the structure and content of a document on the web." It's a hierarchical...
(more)
over 2 years ago
Comment Post #286335 The purpose of `for..of` is not only to provide a different syntax. With this statement, you can loop through any iterable object (you can even create your own). Some objects, for instance, don't have the `length` property or don't support the `[ ]` syntax to get a specific element, so using `for..of...
(more)
over 2 years ago
Comment Post #286335 There's no `=` after `const` in *any* variable declaration. You either declare it as `const variableName;` or `const variableName = someValue;` (the `=` is after the variable name, not after `const` - yes, that was pedantic from my part, sorry) Anyway, this `for..of` code is equivalent to: ```j...
(more)
over 2 years ago
Comment Post #286317 @#56529 The "on the fly variable declaration" is simply the syntax of the [`for..of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of): `for (const child of e.childNodes)` loops through `e.childNodes`, and in each iteration, the next element is set to t...
(more)
over 2 years ago
Edit Post #286334 Initial revision over 2 years ago
Answer A: Delete all occurrences of a character in a webpage with vanilla JavaScript
Some comments and your answer are doing this: ```javascript document.body.innerHTML = document.body.innerHTML.replace(/x/g, ''); ``` But as explained in the comments, this is not a good solution, because it can break the page's HTML. Actually, even if you restrict it to a specific element (in...
(more)
over 2 years ago
Comment Post #286307 @#56529 "*it's harmful to use on an entire document*" - Actually, it's potentially harmful to use in **any** element, if its `innerHTML` contains tags/attributes with the character you're replacing. Let's say you use it in a `div`, and that `div` contains a `textarea` element. Replacing the letter "x...
(more)
over 2 years ago
Comment Post #286307 As already pointed by @#53305, your code might completely destroy the HTML - in your case, it probably "worked" by luck/coincidence, because you're being more restrict: you select only one specific element (the one that has the `new_pages` class), and I guess there were no tags or attributes with the...
(more)
over 2 years ago
Comment Post #286258 @#56529s My bad, `querySelector` returns the first element it finds, while `getElementsByTagName` returns a list of elements (and you should get only the first one). I edited the answer with the correct code
(more)
over 2 years ago
Edit Post #286258 Post edited:
over 2 years ago
Edit Post #286258 Post edited:
over 2 years ago
Edit Post #286258 Initial revision over 2 years ago
Answer A: Move to the edit webpage of a webpage via the keyboard with vanilla JavaScript
You're getting close, just need a few adjustments. Instead of using the `hostname` property, I prefer to use `host`, because it also includes the port (in case the URL has one) - check the documentation for more info. You should also get the `protocol` (which can be `http`, `https`, etc), to bu...
(more)
over 2 years ago
Edit Post #286222 Initial revision over 2 years ago
Answer A: How to uncollapse the first and second tiers of a link tree in JavaScript?
According to the documentation, the `hasAttribute` method expects only one argument (the attribute's name), and it tells only if that attribute is present, regardless of its value. Hence, the return is a boolean (only `true` or `false`). When you pass more than one argument, only the first one is ...
(more)
over 2 years ago
Comment Post #286151 @#53853 How are you compiling those files? I could reproduce the error, but it happens only if I compile `MainClass.java` before `QueueObject.java` (just `javac MainClass.java` before compiling `QueueObject`). If I compile both (such as `javac *.java` or even `javac MainClass.java QueueObject.java...
(more)
over 2 years ago
Edit Post #286084 Initial revision almost 3 years ago
Answer A: How can the Caesar cipher be implemented in Java?
Caesar Cipher originally deals only with letters (ASCII "A" to "Z", without diacritics/accents), so I'm not sure why you included `ۤ$%&` in your answer. And using `indexOf` (as you did) is not very efficient, because it always makes a loop through the string, until the character is found (which me...
(more)
almost 3 years ago
Edit Post #286054 Initial revision almost 3 years ago
Answer A: Mocking methods with arguments
Based on your answer, I guess you just wanted to have a list of unique arguments that were passed to `B::add`. In that case, you could use a `Set` instead of a `List`: ```java // "Type" is whatever type B:add receives as argument Set calledArgs = new LinkedHashSet<>(); @Test public void te...
(more)
almost 3 years ago
Comment Post #286047 May I suggest you to change the exception type in your example? `ArrayIndexOutOfBoundsException` is an unchecked exception, therefore the behaviour you described doesn't happen (it only does when it's a checked exception).
(more)
almost 3 years ago
Comment Post #286031 Let's see if I understood: `B::add` is called multiple times, and you want to check if all calls receives a different argument? Let's say, if it calls `b.add(1)` and `b.add(2)`, the test passes, but if it calls `b.add(1)` twice, it fails. Is `BMock` required for that? Or only checking for a repeat...
(more)
almost 3 years ago
Comment Post #286031 Well, inside `BMock`'s constructor, just add `super(whateverArgsBConstructorExpects)` and that's it :-) Or maybe you could use PowerMockito: see the "Replacing" section in [this link](https://blog.jayway.com/2013/03/05/beyond-mocking-with-powermock/)
(more)
almost 3 years ago
Comment Post #286031 In that case, you could do `BMock extends B` and then set `a.b = new BMock()`
(more)
almost 3 years ago
Comment Post #286031 I'm trying to test your code, but I think there are some details missing. I understood that `A::add` calls `B::add` (as shown in the code), which in turn will call `BMock::add` (`B` code wasn't provided, so I'm guessing). Which one do you want to test? "_If it gets called twice with the same item_...
(more)
almost 3 years ago
Comment Post #286017 @#8196 Well, I think you don't want to change the code for the wrong reasons: "*less lines*" isn't necessarily "better", you should try to write good, clean, readable and correct code, regardless of how many lines you need to achieve that. Sometimes less is better, of course, but sometimes the attemp...
(more)
almost 3 years ago
Comment Post #286017 `Foo` could have a constructor that receives `x`, so it becomes `bar.fun(new Foo(42))`, or static factory methods, such as `Foo.withX(42)` that returns a `Foo` instance with `x` value set.
(more)
almost 3 years ago
Comment Post #285968 Perhaps that's another question, but in `void* p = malloc(n); scanf("%d", p);`, what happens if `n` is less than `sizeof(int)`? I guess it's UB, right?
(more)
almost 3 years ago
Edit Post #285956 Post edited:
fixed link
almost 3 years ago
Edit Post #285965 Post edited:
almost 3 years ago
Edit Post #285965 Initial revision almost 3 years ago
Question Is it OK to use scanf with a void pointer?
I've created a function that calls `scanf` passing a void pointer as argument: ```c void read(const char format, void p) { scanf(format, p); } ``` And tested it with different types: ```c int n; read("%d", &n); printf("read int: %d\n", n); float f; read("%f", &f); printf("rea...
(more)
almost 3 years ago
Suggested Edit Post #285956 Suggested edit:
fixed link
(more)
helpful almost 3 years ago
Edit Post #285917 Post edited:
almost 3 years ago
Edit Post #285939 Post edited:
Remove parts not relevant to the question
almost 3 years ago
Suggested Edit Post #285939 Suggested edit:
Remove parts not relevant to the question
(more)
helpful almost 3 years ago
Edit Post #285939 Post edited:
Fix formatting, remove noise
almost 3 years ago
Suggested Edit Post #285939 Suggested edit:
Fix formatting, remove noise
(more)
helpful almost 3 years ago
Comment Post #285918 @#53280 Thanks for the feedback and suggestions. I've updated the answer.
(more)
almost 3 years ago