Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reversed range using lodash

Is there anything similar to python reversed range in lodash.

In python

   list(reversed(range(0, 4)))
=> [3, 2, 1, 0]
   list(reversed(range(3, 4)))
=> [3]

in lodash

 console.log(_.range(3,4,-1))
[]
   console.log(_.range(0, 4, -1));
[]
like image 741
bsr Avatar asked Feb 14 '23 04:02

bsr


1 Answers

You have the start and stop values reversed.

console.log(_.range(3, -1, -1));
# [ 3, 2, 1, 0 ]

Alternatively you can use the chainable reverse function, with the range, like this

console.log(_.range(0, 4).reverse());
# [ 3, 2, 1, 0 ]

Note: Neither of them is similar to Python 3.x's range function.

like image 132
thefourtheye Avatar answered Feb 15 '23 16:02

thefourtheye