Search code examples
javascriptvcenter

Receive a String in this format: "1-10" and create an array with the amount of numbers in the range


How to Receive a String in this format: "1-10" and create an array with the amount of numbers in the range. Print the array to screen using a for loop.

I.E - "1-5" received so they array will be: {1,2,3,4,5}

create for workflow with vCenter orchestrator.


Solution

  • var input = "1-10";  //SAMPE INPUT DATA.
    var foo = input.split("-");  //PASRING INPUT DATA.
    var answer = []; 
    for(var i = foo[0]; i<= foo[1]; i++){
       answer.push(parseInt(i));  //MAKE AN ARRAY.
    }
    console.log(answer);