The left does not compile... Parameter is a const vector, so you're unable to mutate it. Get link Facebook X Pinterest Email Other Apps July 23, 2022 The left does not compile... Parameter is a const vector, so you're unable to mutate it. science 73 Likes 6 Comments John Theos Ryan Jay I would use neither because of the shitty variables naming and missing of consistency over brackets usage. Ella Belle iterating in 1972 probably more like: addOne: mov rax, 0 for_loop: inc [rsi+rax] inc rax cmp rax, rdi jl for_loop ret Amna Khan Niazi Is the left one even allowed? It's a const, meaning you are not allowed to edit it within the function. Even if it does compile, using the word "const" is just confusing. You are marking the variable for the compiler to let you know if you are messing with things you shouldn't mess with. And then you mess with it. Sumaila Karim We still kind of do this or even worse. But it depends on the language. For instance one of the most modern and youngest languages is Swift. An array of integers by rules would creat a copy of an array in function and would create a copy of each element on access. The first problem should be solvable but the second most likely not. You could not do a.forEach { $0 += 1 } as it would say that “$0” is a “let” which means it is immutable. You could do a.forEach { var i = $0; i += 1 } but this would not change an array. So iterating by index is the only way to do this. But in case as this one we would simply create a new array and resulting code is as simple as a.map { $0 + 1 } Robert Victor Moore Prefer second one. More readable. Yvonne Hines for i in a[] { ++i } Get link Facebook X Pinterest Email Other Apps Comments
The left does not compile... Parameter is a const vector, so you're unable to mutate it. science 73 Likes 6 Comments John Theos
Ryan Jay
Ella Belle
Amna Khan Niazi
Sumaila Karim
Robert Victor Moore
Yvonne Hines