Ad
Fundamentals
Code
Diff
  • class OrdinalNumbers:
        def __init__(self, n):
            self.n = n
            
        def solution(self):
            t = int(str(self.n)[-1])-1
            return str(self.n)+ ("th" if ((self.n>10) and (self.n<20)) else (["st", "nd", "rd"][t:t+1] or ["th"])[0])
    • class OrdinalNumbers:
    • def __init__(self, n):
    • self.n = n
    • def solution(self):
    • if (self.n>10) and (self.n<20): return (str(self.n)+"th")
    • elif (str(self.n)[-1]=="1"): return (str(self.n)+"st")
    • elif (str(self.n)[-1]=="2"): return (str(self.n)+"nd")
    • elif (str(self.n)[-1]=="3"): return (str(self.n)+"rd")
    • else: return (str(self.n)+"th")
    • t = int(str(self.n)[-1])-1
    • return str(self.n)+ ("th" if ((self.n>10) and (self.n<20)) else (["st", "nd", "rd"][t:t+1] or ["th"])[0])
Code
Diff
  • from typing import Sequence, Optional
    
    def missing_integer(sequence: Sequence[int]) -> Optional[int]:
        return next((i + sequence[0] for i, num in enumerate(sequence) if num != i + sequence[0]), None)
    
    • from typing import Sequence, Optional
    • def missing_integer(sequence: Sequence[int]) -> Optional[int]:
    • for i in range(len(sequence)):
    • if sequence[i] != i + sequence[0]:
    • return i + sequence[0]
    • return next((i + sequence[0] for i, num in enumerate(sequence) if num != i + sequence[0]), None)
Code
Diff
  • describeAge=a=>`You're a(n) ${["kid","teenager","adult","elderly"][(a>=13)+(a>=18)+(a>=65)]}`;
    • describeAge=a=>(x=>"You're a(n) "+(["kid","teenager","adult"].find((i,id)=>a<=x[id])||"elderly"))([12,17,64])
    • describeAge=a=>`You're a(n) ${["kid","teenager","adult","elderly"][(a>=13)+(a>=18)+(a>=65)]}`;