0 votes
1 view
in RPA by (5.3k points)

I am trying to get a string with a number where, if there is a match between the former and later number add it to a sum total, so 55412 will be 5 and 112332 will be 1 + 3 so 4. This is coded in typescript, the problem is my code doesn't output anything.

function uipath(e, arg) { let stringToInt = new StringToInt("5514133"); stringToInt.charCompareAndSum(); stringToInt.stringSplit(); alert (stringToInt.getSumList.toString); } class StringToInt { private argumentString : string ; private numberArr : Array<string>; private sumList : number; constructor( arg: string) { this.argumentString = arg ; } stringSplit() { this.numberArr = this.argumentString.split(/(?=.)/u); } charCompareAndSum() { for(var i = 0; i < this.numberArr.length -1; i++ ) { if (this.numberArr[i] == this.numberArr[i+1]) { this.sumList = this.sumList + +this.numberArr[i]; } } } get getSumList():number { return this.sumList; } }

1 Answer

0 votes
by (9.5k points)

 

call your functions

stringToInt.getSumList.toString

Should be

stringToInt.getSumList().toString()

it might not print anything because

stringToInt.getSumList

Evaluates to the getSumList function itself, then

getSumList.toString

Evaluates to undefined since the function doesn't have a toString property.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...