Merge Sort in Go and Javascript

Here’s my implementation of the Mergesort algorithm in Golang package main import ( "fmt" "io/ioutil" "math/rand" "strconv" "strings" "time" ) func main() { start := time.Now() arr := randArr(20) // Merge sort array fmt.Println("\n Sorted \n", mergeSort(arr)) fmt.Println("Sorted in: ", time.Since(start)) } // Function to generate random array func randArr(size int) []int { arr := make([]int, size, size) rand.Seed(time.Now().UnixNano()) for i := 0; i < size; i++ { arr[i] = rand.Intn(99) } return arr } // Merge sort accepts an array and recursively sorts it func mergeSort(arr []int) []int { if len(arr) < 2 { return arr } middle := (len(arr)) / 2 return merge(mergeSort(arr[:middle]), mergeSort(arr[middle:])) } // Merges two arrays into one func merge(left, right []int) []int { var sortedArr []int // Check for inversions while array for len(left) > 0 && len(right) > 0 { if left[0] <= right[0] { sortedArr = append(sortedArr, left[0]) left = left[1:] // Just like shift(), remove first and return slice } else { sortedArr = append(sortedArr, right[0]) right = right[1:] // Just like shift(), remove first and return slice } } // Append to sortedArr if no inversions and for len(left) > 0 { sortedArr = append(sortedArr, left[0]) left = left[1:] // Just like shift(), remove first and return slice } for len(right) > 0 { sortedArr = append(sortedArr, right[0]) right = right[1:] // Just like shift(), remove first and return slice } return sortedArr } and here’s in Javascript ...

May 26, 2019 · 2 min · oschvr

Understanding Recursion

Rather than using the popular joke about recursion (see bottom), I’ll reference a very peculiar adage which makes use of this particular mental model: The Hogstadter’s Law, states that: It always takes longer than you expect, even when you take into account Hofstadter’s Law. See what happened there? The law is a self-referential adage, that tries to describe the widely experienced difficulty of accuratelly estimate the time it will take to complete tasks of substancial complexity. ...

May 17, 2019 · 4 min · oschvr

Shortest Fibonacci

Here’s an incredibly short anonymous fibonacci function in Js. It takes a parameter n to calculate the fibonacci number at position n ((n) => (n <= 1 ? n : n - 1 + n - 2))(5);

May 15, 2019 · 1 min · oschvr

3 Meses sin Facebook

Última Actualización: 09/Junio/2018 A ver si se acuerdan de algún compañero del kinder/primaria primaria, cuyos padres neo-liberales, le prohibían ver televisión en favor de actividades diurnas al aire libre. Ese mismo compañerito que, forzado por la voluntad de sus padres, se quedaba fuera de las discusiones de quien era el ‘Chico del Pórtico’, episodio de Hey Arnold en Nickelodeon, o quien podía decir ‘Omelette du Fromage’ durante un día entero, como le pasó al Dexter en El Laboratorio de Dexter de Cartoon Network. ...

June 8, 2018 · 5 min · oschvr

¿Qué es un chatbot?

¿Qué es un chatbot? Un chatbot es un servicio impulsado por reglas y aveces inteligencia artifical con el que se interactúa a través de una interfaz de tipo chat. Sacado de la plática de Iván Ruiz, en Mobile Day 2017. Chatbot as a Service Los chatbots fungen como servicio para transformar sitios web en Experiencias Conversacionales Enrolamiento Uno de los casos de uso de los chatbots es el enrolamiento de usuarios a una plataforma. ...

November 17, 2017 · 1 min · oschvr