letsuits=["hearts","spades","clubs","diamonds"];functionpickCard(x:{suit:string;card:number;}[]):number;functionpickCard(x:number):{suit:string;card:number;};functionpickCard(x:any):any{// Check to see if we're working with an object/array// if so, they gave us the deck and we'll pick the cardif(typeofx=="object"){letpickedCard=Math.floor(Math.random()*x.length);returnpickedCard;}// Otherwise just let them pick the cardelseif(typeofx=="number"){letpickedSuit=Math.floor(x/13);return{suit:suits[pickedSuit],card:x%13};}}interfaceIPickCard{(x:{suit:string;card:number;}[]):number(x:number):{suit:string;card:number;}}typePickCard=|((x:{suit:string;card:number;}[])=>number)|((x:number)=>{suit:string;card:number;});consty:PickCard=pickCard;constx:IPickCard=pickCard;
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Function overloading seems to work similar