Hi,
I want to separate arguments and their types as given in the following string:
"(address to, uint amount)"
The number of arguments are not restricted to 2. Thus I need a loop. For the above, I am doing without a loop using:
I want to perform above command using a loop but I can’t understand how to use a 2d array. The complete code is given below:
/*The output is:
Using network 'development'.
arg=(address
arg=
arg=to
arg=
arg=uint
arg=amount)
*/
I also want to replace the last two for loops using a single loop. Somebody please guide me.
Zulfi.
I want to separate arguments and their types as given in the following string:
"(address to, uint amount)"
The number of arguments are not restricted to 2. Thus I need a loop. For the above, I am doing without a loop using:
JavaScript:
argArr_TypeAndNameSeparated1=argArr_TypeAndNameCombined[0].split(' ')
argArr_TypeAndNameSeparated2=argArr_TypeAndNameCombined[1].split(' ')
I want to perform above command using a loop but I can’t understand how to use a 2d array. The complete code is given below:
Code:
const path = require("path");
const fs = require("fs");
module.exports = async function(callback)
{
try {
let argStr = "(address to, uint amount)"
let argArr_TypeAndNameCombined = []
let argArr_TypeAndNameSeparated= "" //[[], []]
argArr_TypeAndNameCombined = argStr.split(',');
find_the_arguments(argStr)
}
catch (error) {
console.log(error)
}
callback();
}
function find_the_arguments(argStr) {
argArr_TypeAndNameCombined = argStr.split(',')
//argArr_TypeAndNameCombined[0] = (address to
//argArr_TypeAndNameCombined[1] = uint amount)
argArr_TypeAndNameSeparated1=argArr_TypeAndNameCombined[0].split(' ')
argArr_TypeAndNameSeparated2=argArr_TypeAndNameCombined[1].split(' ')
for(let i=0; i<argArr_TypeAndNameSeparated1.length; i++){
console.log("arg="+argArr_TypeAndNameSeparated1[i])
}
for(let i=0; i<argArr_TypeAndNameSeparated2.length; i++){
console.log("arg="+argArr_TypeAndNameSeparated2[i])
}
}
/*The output is:
Using network 'development'.
arg=(address
arg=
arg=to
arg=
arg=uint
arg=amount)
*/
I also want to replace the last two for loops using a single loop. Somebody please guide me.
Zulfi.