Skip to main content
added 81 characters in body
Source Link
Mihai Alexandru-Ionut
  • 48.6k
  • 14
  • 106
  • 132

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => start < end ? [...Array(end - start)].map((_, i) => start + i) : []; console.log(range(1,9));

Also, returns an empty array for case when start is greater than end.

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => start < end ? [...Array(end - start)].map((_, i) => start + i) : []; console.log(range(1,9));

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => start < end ? [...Array(end - start)].map((_, i) => start + i) : []; console.log(range(1,9));

Also, returns an empty array for case when start is greater than end.

added 19 characters in body
Source Link
Mihai Alexandru-Ionut
  • 48.6k
  • 14
  • 106
  • 132

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => start < end ? [...Array(end - start)].map((_, i) => start + i); : []; console.log(range(1,9));

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => [...Array(end - start)].map((_, i) => start + i); console.log(range(1,9));

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => start < end ? [...Array(end - start)].map((_, i) => start + i) : []; console.log(range(1,9));

deleted 4 characters in body
Source Link
Mihai Alexandru-Ionut
  • 48.6k
  • 14
  • 106
  • 132

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => [...Array(end - start + 1)].map((_, i) => start + i); console.log(range(1,9));

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => [...Array(end - start + 1)].map((_, i) => start + i); console.log(range(1,9));

Is there a simple way to create the list in JavaScript?

No, but you can create your own solution using ES features like map and spread syntax.

var range = (start, end) => [...Array(end - start)].map((_, i) => start + i); console.log(range(1,9));

Source Link
Mihai Alexandru-Ionut
  • 48.6k
  • 14
  • 106
  • 132
Loading