1

Very new to Javascript, as I'm primarily using it to execute commands in Selenium IDE. I've been using the range function provided by Mozilla's documentation for the array.from() method. This is how I put it together in Selenium:

const range = (start,stop,step) =>
  Array.from(
    { length: (stop - start) / step + 1},
    (_, i) => start + (i * step)
  );
  return(range(179,199,1))

Is there a way to return more than one range? Why doesn't this work? (In Selenium IDE, it completely skips over this command.) Is it because it's a multi-dimensional array?

const range = (start,stop,step) =>
  Array.from(
    { length: (stop - start) / step + 1},
    (_, i) => start + (i * step)
  );
  return (range(179,199,1), range(201,210,1))
2
  • I seems you use an arrow function without braces, and then use return and think that the return expression is associated with the arrow function, which in fact is not true.
    – MaxG
    Commented Nov 29, 2019 at 19:05
  • 1
    The other problem you have, is trying to run both the return functions wrapped in parentheses, which evaluates the first value, does nothing with it and then evaluates the second value - the one you return. If you wrap both range expressions in square brackets [] brackets you'll see everything works
    – MaxG
    Commented Nov 29, 2019 at 19:13

1 Answer 1

2

you used a () where you have to use either object {} or array [] to get multiple ranges as below

const range = (start, stop, step) => Array.from({
  length: (stop - start) / step + 1
}, (_, i) => start + (i * step));
var a = () => ([range(179, 199, 1), range(201, 210, 1)])
var b = () => ({"range1":range(179, 199, 1),"range2": range(201, 210, 1)})
console.log(a());
console.log(b());

3
  • This works outside of Selenium, but for some reason doesn't seem compatible with the IDE.
    – klex52s
    Commented Nov 29, 2019 at 21:35
  • which IDE are you using? Commented Nov 29, 2019 at 22:24
  • This is Selenium's IDE (which is probably not what you think when you think IDE). It's basically a GUI that provides record and playback to test web features.
    – klex52s
    Commented Dec 2, 2019 at 14:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.