+ 7

Code not compatible ?

So let's say that in python I have this function called rotate_90(m) that will take a matrix m and rotate its terms 90 degrees clockwise. Now if I want to make the function rotate_270(m), knowing that 270=9*3 I'll do: def rotate_270(m): for i in range(3): m=rotate_90(m) return m Now let's say I have this same function rotate_90(m) but in javascript. If I try to do function rotate_270(m){ for(i=0;i!=3;i++) m=rotate_90(m) return m } For some reason it doesn't seem to work.... Could somebody tell me why please ?

14th Jun 2019, 3:46 PM
Uni
Uni - avatar
4 Respostas
+ 5
maybe try: for( var i=0; i < 3; i++) m=rotate_90(m) I don’t think this will fix the problem though, it should just make i a local variable, but maybe that’s the issue?
14th Jun 2019, 4:08 PM
Jackson O’Donnell
+ 9
Indeed I tried with for(let i=0;i!=3...etc) and it worked ! Thank you Jackson O’Donnell !
14th Jun 2019, 4:24 PM
Uni
Uni - avatar
+ 8
Jackson O’Donnell sorry my question wasn't clear.... So in python it works but not in javascript: in javascript I believe that it runs forever because if I alert the output, that alert will never show up...
14th Jun 2019, 4:02 PM
Uni
Uni - avatar
+ 1
is the rotate_90(m) written in JS as well? It may be an issue in that function. And what is your error? Does it just not run? Run forever? Wrong output?
14th Jun 2019, 3:57 PM
Jackson O’Donnell