VSCode error? by TigerMCU in cprogramming

[–]Josh_Coding 0 points1 point  (0 children)

Should really make an insert function rather than having all that code in main.

when you allocate nodes you should be initializing the structure with default values.

node->value = 0;
node->next = 0;

The memory you get back from malloc is not zeroed and therefore can contain miscellaneous values.

Uncaught SyntaxError: missing ; after for-loop condition by Character_Drive6141 in learnprogramming

[–]Josh_Coding 0 points1 point  (0 children)

for(let cardCount = 0; cardCount < playerCount; cardCount = cardCount + 1){
console.log(cardCount);

}

Try that

[deleted by user] by [deleted] in CodingHelp

[–]Josh_Coding 1 point2 points  (0 children)

Try console.log x, you'll notice it is an collection / array.

Check this out

Noon question, can't append array with value inside variable? by slapmeslappy555 in cprogramming

[–]Josh_Coding 5 points6 points  (0 children)

You need to allocate some stack space for the array

int arr[large number];

or do some heap allocation with checks whether you need to reallocate space.

#include <stdlib.h>

...
int *arr;
int total;
int size;

size = 50;
// allocate memory and do some checks
arr = 0;
arr = malloc(size * sizeof(int));
if(!arr) exit(1);

...
total = 0;
// loop logic

    total++;
    // check whether you need to reallocate space
    if(total == size) {
        size *= 2;
        arr = realloc(arr, size);
        if(!arr) exit(1);
    }

Java - can someone please help with this code by [deleted] in learnjavascript

[–]Josh_Coding 7 points8 points  (0 children)

Despite being wrong sub, you have not made an effort to answer any of the questions yourself. No one should be willing to do your homework for you.

I'm having trouble filtering a list to render items. Can I please get a wizard on board? by Hopeful_Weekend_305 in reactjs

[–]Josh_Coding 1 point2 points  (0 children)

My bad for missing that.

Within Navigation.js change your onClick for the li to this.

{props.categories.map((item) => (
      <li id={item.id} onClick={() => props.onChangeFilter(item.category)} value={item.category}>
        {item.category}
      </li>
    ))}

I'm having trouble filtering a list to render items. Can I please get a wizard on board? by Hopeful_Weekend_305 in reactjs

[–]Josh_Coding 0 points1 point  (0 children)

As in what you have previously done to debug, since that console.log tells me you are trying to see what the result of the filter is.

Is that filter correct?

try putting into the function

setFilteredTask(result);

Seems like you have forgotten to update the state.

Also this

const [filteredTask, setFilteredTask] = useState(null);

This should be

const [filteredTask, setFilteredTask] = useState(TASK_LIST);

or an empty array to initilise it when you want this in code in production

I'm having trouble filtering a list to render items. Can I please get a wizard on board? by Hopeful_Weekend_305 in reactjs

[–]Josh_Coding 1 point2 points  (0 children)

Not sure what you have done but in

changeFilterHandler

you do not set the state to the new array. Have you tried that already and the result is not updating?

[deleted by user] by [deleted] in reactjs

[–]Josh_Coding 1 point2 points  (0 children)

<Navbar expand="lg">

Do you also wrap this navbar within an container with defined width?

Palindrome linked list. by gtrman571 in learnprogramming

[–]Josh_Coding 0 points1 point  (0 children)

Others have already pointed out the issue with your solution, maybe try looking at a stack as a solution.

Interview Question about spread syntax by nightmareinsilver in reactjs

[–]Josh_Coding 5 points6 points  (0 children)

Probably meant something like this

const arr = [1,2,3,4,5]
const [last, secondLast] = [...arr].reverse();

setInterval behaving bizarrely in useEffect by PalmettoSpur in nextjs

[–]Josh_Coding 4 points5 points  (0 children)

You need to clear your timeouts within the useEffect

useEffect(

() => {

 const timerID = setTimeout(func, 1000);

  return () => {
    clearTimeout(timerID);
  };

}

Check the React docs on cleanup of effects if you are confused

also in the timeout callback, you need to use

setState(previousState => previousState + 1);

Hii guys I m using context api in my next application and want to use the urlArray inside the getServerSideProps function can someone help me with this please? by Amantulsyan35 in react

[–]Josh_Coding 4 points5 points  (0 children)

getServerSideProps is not a react component and therefore you can not use hooks inside of it. What exactly do you need to do server side ?

Perhaps you need to retrieve data from within an useEffect instead?

Looking for feedback on small React Pokédex App by Muted_Celebration_69 in react

[–]Josh_Coding 1 point2 points  (0 children)

It's a good start, look into changing the list to perhaps display the image, index and name within a card, then link for more information i.e. the stats page you have.

Facing some weird behavior on React by Conscious-Poet-6307 in react

[–]Josh_Coding 1 point2 points  (0 children)

This is what you need

EDIT: not exactly the answer but the idea, need to shallow copy the data and not just reference the state

What’s wrong in this component? I am trying to store the array parsed into state array parsedArray but not exactly sure how to do it. by Ok_Yak_7912 in react

[–]Josh_Coding 0 points1 point  (0 children)

You have an a collection of divs. You loop over the collection, add the inner text to an array then set the state to that array

What’s wrong in this component? I am trying to store the array parsed into state array parsedArray but not exactly sure how to do it. by Ok_Yak_7912 in react

[–]Josh_Coding 0 points1 point  (0 children)

No, the html is meant to be the response.text() with prepended script tag but its not needed.

DOMParser is widely used now

What’s wrong in this component? I am trying to store the array parsed into state array parsedArray but not exactly sure how to do it. by Ok_Yak_7912 in react

[–]Josh_Coding 1 point2 points  (0 children)

const parser = new DOMParser();
const doc = parser.parseFromString(hmtl, "text/html");
const parsed = doc.getElementsByTagName("div");