“Convertir la fonction Python en javascript onlie” Réponses codées

Convertir la fonction Python en javascript onlie

for i in range(len(Times)):
    mini=i  #To store minimum time index
    for j in range(i,len(Times)):
        #updating the minimum index
        if(Times[mini]>Times[j]): 
            mini=j
    #swapping the ith element with minimum element
    Times[mini],Times[i]=Times[i],Times[mini]

print("Fastest to slowest order: ",Times)
Troubled Tamarin

Convertir la fonction Python en javascript onlie

def compute_interesting_times(s, t):
    def convert_number(x):
        pad = ''
        if x < 10:
            pad = '0'
        return pad + str(x)
        
    # Check times
    if s > t:
        raise ValueError("The init time is greater than the finishing time")
        
        
    # Parse times
    h_c, m_c, s_c = map(lambda x: int(x), s.split(':'))
    h_f, m_f, s_f = map(lambda x: int(x), t.split(':'))
    total = 0
    
    while not (h_c == h_c and m_c == m_f and s_c == s_f):
        # Transform the numbers into a proper string and
        # check if we have to increase the total
        a = '{}{}{}'.format(convert_number(h_c),
                            convert_number(m_c), 
                            convert_number(s_c))
        if len(set(a)) <= 2:
            total += 1
        
        # Update the time counters
        s_c += 1
        if s_c == 60:
            s_c = 0
            m_c += 1
            if m_c == 60:
                m_c = 0
                h_c += 1

    # Check if the finishing time is an interesting time
    a = '{}{}{}'.format(convert_number(h_c),
                            convert_number(m_c), 
                            convert_number(s_c))
    if len(set(a)) <= 2:
        total += 1

    return total
Modern Millipede

Réponses similaires à “Convertir la fonction Python en javascript onlie”

Questions similaires à “Convertir la fonction Python en javascript onlie”

Plus de réponses similaires à “Convertir la fonction Python en javascript onlie” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code