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 #287682 Actually, hours and minutes are not being used, so you could also remove them: https://jsfiddle.net/86x0jtu7/1/
(more)
almost 2 years ago
Comment Post #287682 `getSeconds`, `getMinutes` and `getHours` are functions (actually methods, but anyway), and they need to have parenthesis to be called - so change them to `getSeconds()`, `getMinutes()` and `getHours()`, and it'll work: https://jsfiddle.net/7tar9uvw/
(more)
almost 2 years ago
Comment Post #286994 > "*The strikethrough on 'd'?*" Yes! One idea to make it easier to find: the line that was changed has a different highlighting, which means the system *already knows* that the difference is on that specific line. Maybe it could show only that line (or have an option to toggle between "show all...
(more)
over 2 years ago
Comment Post #286994 Regarding the second case, there's an example [here](https://software.codidact.com/posts/284597/history): in edit #6, only one character was removed, and there's a strikethrough showing that. It's still hard to find because it's only one single char in a long post, but I guess we can consider this is...
(more)
over 2 years ago
Edit Post #284597 Post edited:
Don't change this message, it's displayed by Git itself
over 2 years ago
Comment Post #286948 IMO, enabling articles would be great. Sometimes you just want to write a post explaining "what is X and what it's used for". And for those cases, the question tends to be very silly ("*I've heard of X, but what is it?*). An article could simply skip this "made up a question" part and go straight ...
(more)
over 2 years ago
Edit Post #284597 Post edited:
over 2 years ago
Edit Post #286764 Post edited:
formatting, minor fixes, remove unrelated tags
over 2 years ago
Suggested Edit Post #286764 Suggested edit:
formatting, minor fixes, remove unrelated tags
(more)
helpful over 2 years ago
Edit Post #286774 Post edited:
over 2 years ago
Edit Post #286774 Post edited:
over 2 years ago
Edit Post #286774 Initial revision over 2 years ago
Answer A: How to use grep to print only specific word from a string
I wouldn't use `grep`. As the other answers already said, it's not the right tool for this job. Considering your specific case (fields separated by `/`), `basename` is the most straighforward way, as stated in Dirk's answer. I just want to provide some other alternatives. `cut` The `cut`...
(more)
over 2 years ago
Edit Post #284597 Post edited:
over 2 years ago
Edit Post #286516 Post edited:
Grammar/format fixes
over 2 years ago
Suggested Edit Post #286516 Suggested edit:
Grammar/format fixes
(more)
helpful over 2 years ago
Comment Post #286307 As explained in [other answer](https://software.codidact.com/posts/286304/286334#answer-286334) and in [another comments thread](https://software.codidact.com/comments/thread/6166), this code can break the HTML structure and it's not recommended.
(more)
over 2 years ago
Edit Post #286480 Post edited:
formatting improved / removed non-related tags
over 2 years ago
Suggested Edit Post #286480 Suggested edit:
formatting improved / removed non-related tags
(more)
helpful over 2 years ago
Edit Post #286440 Post edited:
rephrasing/fixes grammar issues, fix code block
over 2 years ago
Suggested Edit Post #286440 Suggested edit:
rephrasing/fixes grammar issues, fix code block
(more)
helpful over 2 years ago
Edit Post #286409 Post edited:
over 2 years ago
Comment Post #286409 @#56529 I've made a quick test here and it seems that the argument is required. If you don't want any option to be passed, just use an empty object, and it'll use the defaults (as [described in the docs](https://davidjbradshaw.github.io/iframe-resizer/#options)): ~~~javascript iFrameResize({}, '#...
(more)
over 2 years ago
Edit Post #286406 Post edited:
Add link to the code's origin, to provide more context
over 2 years ago
Edit Post #286409 Initial revision over 2 years ago
Answer A: What is [{options}] in JavaScript?
Given the link where the code comes from (based on your other question), this is just a, let's say, "free-form/pseudo-code/documentation example". It's not a valid JavaScript code. It's more like a free-format "syntax" intended to provide a general documentation about what parameters are expected...
(more)
over 2 years ago
Suggested Edit Post #286406 Suggested edit:
Add link to the code's origin, to provide more context
(more)
helpful over 2 years ago
Edit Post #286335 Post edited:
Formatting, added tags
over 2 years ago
Suggested Edit Post #286335 Suggested edit:
Formatting, added tags
(more)
helpful over 2 years ago
Comment Post #286349 @#56529 > "*from my experience with elementary and basic JavaScript tutorials it's not common*" Well, from my experience (I'm not bragging about it, but it goes beyond basic), it's not uncommon. Regarding readability, well, that's very subjective, and setting an initial value is not always nece...
(more)
over 2 years ago
Comment Post #286357 @#56529 Based on your last comments (here and in another posts), I guess the main issue is to understand recursion and how this relates to DOM tree traversal. I've edited the answer and added **lots** of stuff to explain what's going on with this code. I also suggest you to read Dirk's answers a...
(more)
over 2 years ago
Edit Post #286357 Post edited:
over 2 years ago
Comment Post #286351 @kalispero Sorry, I had too many unread notifications and probably missed this one
(more)
over 2 years ago
Comment Post #286372 "*Operator precedence rules of JavaScript or of Math?*" Both: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence - https://en.m.wikipedia.org/wiki/Order_of_operations
(more)
over 2 years ago
Comment Post #286372 Zero multiplied by anything is zero, so `0 * 42` is zero. Thus, `-1 + 0 * 42` is `-1 + 0` (because of operator precedence rules, multiplication is made before the addition), which results in `-1`.
(more)
over 2 years ago
Comment Post #286358 The code is traversing the DOM tree, just like I imagine a tree-walker would do. I would say it's an *actual* tree walker, then :-)
(more)
over 2 years ago
Comment Post #286358 `e.childNodes.forEach(replaceIn(document.body))` is wrong, the correct is `e.childNodes.forEach(replaceIn)` - that's because the `forEach` method receives the function that will be called for each element. By doing `replaceIn(document.body)`, you're calling the function, and the result is being passe...
(more)
over 2 years ago
Comment Post #286358 Consider the analogy of the labyrinth in [Dirk's answer](https://software.codidact.com/posts/286349/286352#answer-286352): to do the task in all rooms you need to visit all of them. There's no way to do that without actually visiting every single room. In a similar way, you can't replace all the n...
(more)
over 2 years ago
Comment Post #286334 The non-dangerous solution is what's already suggested, anything else will be a workaround and won't properly work for all cases. The problem with `innerHTML` is that it's a single string with everything in it (tags, attributes, etc, all in a long, unique string). To break it into parts, you'll ne...
(more)
over 2 years ago
Comment Post #286358 @#56529 You simply call the function with the element: `replaceIn(document.querySelector('whatever'))`. Or, as it was made in your other question: `replaceIn(document.body)`. There's no `replaceAll` because the elements in a page are organized in a DOM-tree - it's a hierarchical structure (as exp...
(more)
over 2 years ago
Comment Post #286351 @#56529 Note that `(x == 42)` is a comparison (it's checking if `x` is equals to `42`), so the result is a boolean (it can be `true` or `false`). In this case, the result is `true`. But when you multiply a boolean and a number, the boolean is automatically converted to a number (JavaScript does a ...
(more)
over 2 years ago
Comment Post #286357 @#56529 > "*I am starting to think that my problem with this code is not the if-else*" I agree. The logic behind `if`/`else` is always the same: if the condition is true, do this, otherwise do that. Perhaps your issue is actually understanding what the "_this_" and "_that_" are doing in this pa...
(more)
over 2 years ago
Comment Post #286351 @#56529 You must assign a value to `x` before running that: ```javascript x = 42; x = (x == 42) * -1 + (x != 42) * x; ```
(more)
over 2 years ago
Edit Post #286358 Initial revision over 2 years ago
Answer A: How to make this treewalker code having a regular for loop or a forEach() method?
> I personally think its syntax is confusing. Well, it's just a matter of getting used to it, I guess :-) Anyway, this code is just looping through all `childNodes` and in each iteration it calls the `replaceIn` function, passing the element as argument. Therefore, you could replace the ...
(more)
over 2 years ago
Edit Post #286357 Initial revision over 2 years ago
Answer A: How this recursive treewalker works?
> How this recursive treewalker works? To understand what the code does, we need to first see what problem it's trying to solve and why it needs to be solved this way. Let's consider this HTML: ```html Whatever site abcdef ``` It's rendered as: Rendered HTML And it's repr...
(more)
over 2 years ago
Comment Post #286349 `let node;` **is** "regular JavaScript". It's just declaring a variable without assigning an initial value, which is not uncommon. I didn't assign a value because it wasn't needed, as this will be made in the loop. Of course you could do: ```javascript let node = 1; while ((node = walker.nextNod...
(more)
over 2 years ago
Comment Post #286349 Perhaps you could rephrase the question to "how this recursive function works", because that seems to be the main issue (once you understand this, the `else` and `for` become just minor details, IMO)
(more)
over 2 years ago
Comment Post #286349 Well, there is: https://software.codidact.com/posts/286304/286334#answer-286334 :-) If I understood correctly, the piece of code that uses `createTreeWalker` does that.
(more)
over 2 years ago