Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sleep sort

/* For each number in an array, an asynchronous timer lasting the
length of the number is set, printing the number once the timer is up.*/
const numbers = [1, 6, 3, 5, 4, 2]

numbers.forEach(num => {
    setTimeout(() => console.log(num), num)
});
Comment

Sleep Sort

from time import sleep
from threading import Timer

def sleep_sort(values):
    sleepsort.result = []
    def add1(x):
        sleepsort.result.append(x)
    mx = values[0]
    for v in values:
        if mx < v: mx = v
        Timer(v, add1, [v]).start()
    sleep(mx+1)
    return sleepsort.result

x = [3,2,4,7,3,6,9,1]
print sleep_sort(x)

#[1, 2, 3, 3, 4, 6, 7, 9]
Comment

PREVIOUS NEXT
Code Example
Javascript :: noconflict jquery 
Javascript :: console.dir depth 
Javascript :: javascript string to int 
Javascript :: how to convert the file pdf into json format in python 
Javascript :: sass node sass loder 
Javascript :: javascript filter array of objects by id 
Javascript :: localstorage is not defined 
Javascript :: how to generate 6 random alphanumerals in js 
Javascript :: remove negative sign from number javascript 
Javascript :: js how to know the laster number of a number 
Javascript :: lodash combine permissions 
Javascript :: how to add youtube insta icon to next js 
Javascript :: reverse number javascript 
Javascript :: javascript enable a button once an input text filled 
Javascript :: nodefetch of ES modules is not supported. 
Javascript :: avaScript slice() With Negative index 
Javascript :: puppeteer clear input 
Javascript :: min object value in array 
Javascript :: replace globally in javascript 
Javascript :: convert camelcase to sentence case javascript 
Javascript :: jquery scroll to element 
Javascript :: chart js rotating the x axis labels 
Javascript :: node js load animation 
Javascript :: input type text js 
Javascript :: router-link vue 
Javascript :: disable copy past jquery 
Javascript :: codewars js Find the first non-consecutive number 
Javascript :: javascript modify url without reloading page 
Javascript :: get current scroll height javascript 
Javascript :: node fs get directory creation date 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =