How to solve the "magic number" linter warning

mnd: Magic number: 2, in detected (gomnd)

  for i := 1 + len(t.list)/2; i >= 0; i-- {

How am I supposed to write my code, according to this linter ? I need to iterate on the first half of a list, therefore I divide its len by two. Can this be done better ?

The obvious solution is to stop using the go-mnd linter.

Failing that, try something like

	const one, two = 1, 2
	for i := one + len(t.list)/two; i >= 0; i-- {

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