Interacting with ChatGPT to Generate NR code

Guys, more for the beginners/middle range guys here - but here is a series of interactions i did with ChatGPT that ended up with a great result and what looks like pretty good code to me

This took almost no time - other than cutting and pasting the results and then doing a deploy each time to check

Its quite unbelievable how forgiving it is and also how well it allows you to drill down on a problem through a series of steps rather than having to know it all at the start

Very informative and the description of what each of the code segments does is quite informative - a good tool to send beginners to when they ask some basic question - and something that would give code that is quite similar each time

Craig

1 Like

You should prompt it to not use var

1 Like

I knew there would be a stickler somewhere !

Good Pickup

Craig

I use 'var' a lot, is there a reason not to use it?

It is better to use const or let as appropriate, as it allows the interpreter to generate more efficient code and will trap some bugs that might otherwise get through.

1 Like

var is not scope aware
let is scope aware

const MyArrayOfArray = [
     [1,2,3],
     [4,5,6],
     [7,8,9]
]

for(var i = 0;i<MyArrayOfArray.length;i++) {

   const Collection = MyArrayOfArray[i]

   /* The below will also increment our first for loop (i is global) - Not good */
   for(var i = 0;i<Collection.length;i++) { 
    ...
   }
}

for(let i = 0;i<MyArrayOfArray.length;i++) {

   const Collection = MyArrayOfArray[i]

   /* This wont */
   for(let i = 0;i<Collection.length;i++) { 
    ...
   }
}

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.