How to Reverse Sort Integers in Go
The challenge
The two oldest ages function/method needs to be completed. It should take an array of numbers as its argument and return the two highest …
Read Article →129 articles about go development, tools, and best practices
The two oldest ages function/method needs to be completed. It should take an array of numbers as its argument and return the two highest …
Read Article →Implement a function which behaves like the uniq
command in UNIX.
It takes as input a sequence and returns a sequence in which all …
Read Article →If you need to check if a string
is empty in Go, then there are two possible ways to immediately verify this:
if len(s) …
Read Article →
If you need to read a file line by line in Go, then you can use the bufio
package as follows:
package main
import (
"bufio" …
Read Article →
Consider the function
f: x -> sqrt(1 + x) - 1
at x = 1e-15
.
We get: f(x) = 4.44089209850062616e-16
This function involves the …
Read Article →Write a function partlist
that gives all the ways to divide an array of at least two elements into two non-empty parts.
If you need to check if a file exists using Go, then you can use one of the following methods, depending on the version of Go you may be using.
If you …
Read Article →If you need to convert a string
to an int
in Go, then you should use the strconv.Atoi
function:
package main
import (
"strconv" …
Read Article →
If you need to convert an int
to a string
in Go, then you should use the strconv.Itoa
function:
package main
import (
"strconv" …
Read Article →
If you are using a version of Go >= 1.10, then you should be using the newer strings.Builder
pattern as follows:
package main
import ( …
Read Article →
If you have a map
in Go and want to only perform an action if it contains a certain key, then you can do so easily:
if val, ok := …
Read Article →
If you need to loop forever, or infinitely, in your Go code, then you have 2 options:
for {
// your code here
}
for true {
// …
Read Article →