I want to know whether why this seemingly OK code, does not work. Is there something wrong going with the callback? Can you use recursive function inside a method?
What I want to do here is, I want to call use a method inside the class G964
, which will result something like this:
argument: (3,5)
return result: [3,2,1,1]
export class G964 {
public static sqInRect(l: number, w: number): number[] {
if (l === w) { return null; }
var recur = function(arr:number[]) {
let minusResult:number = arr.slice(-2)[0] - arr.slice(-2)[1];
if (minusResult > 0) {
arr.push(minusResult);
recur(arr);
} else {
arr.shift();
return arr;
}
}
let testArr = [ l, w ].sort((a:number, b:number) => a-b).reverse();
return recur(testArr);
}
}