-1

here is my code and the error i am getting.

quicksort(low:number,high:number){
if(low<high){

let pi=this.partition(low,high); 
this.quicksort(low,pi-1);
}
}
partition(low:number,high:number){
/* my partition logic*/
}

error img

What is it that i have to do ? Is it not possible to declare local variables of a number type in typescript?

2
  • 1
    set number as a return datatype for partition(low, high) function Jun 17, 2020 at 8:55
  • or better implement the partition function. right now it returns undefined, hence the error
    – Aleksey L.
    Jun 17, 2020 at 9:06

1 Answer 1

2

Add a return-type to you partition-funtion:

partition(low:number,high:number): number {
    /* my partition logic*/
}
4
  • 2
    While this is good practice, it's worth noting that it's not always necessary. function x(){ return Math.random(); } , TS usually catches on with what you had in mind.
    – matek997
    Jun 17, 2020 at 8:56
  • 2
    Using (strict) types helps finding errors early and makes your programm more stable
    – SAM
    Jun 17, 2020 at 8:57
  • 3
    @matek997 you can cast it if needed Jun 17, 2020 at 8:59
  • or better implement the partition function. right now it returns undefined, hence the error
    – Aleksey L.
    Jun 17, 2020 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.