Function frequency: Difference between revisions
→{{header|Go}}: top ten
(Go solution) |
(→{{header|Go}}: top ten) |
||
Line 16:
"io/ioutil"
"os"
"sort"
)
Line 44 ⟶ 45:
return true
})
cs := make(calls, 0, len(m))
for k, v := range m {
}
sort.Sort(cs)
for i, c := range cs {
fmt.Printf("%-20s %4d\n", c.expr, c.count)
if i == 9 {
break
}
}
}
type call struct {
count int
}
type calls []*call
func (c calls) Len() int { return len(c) }
func (c calls) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c calls) Less(i, j int) bool { return c[i].count > c[j].count }</lang>
Output, when run on source code above:
<pre>
len 3
▲1 string
f.Offset 2
make 2
fmt.Printf 1
a.Pos 1
string 1
skeys byron 81> 1
append 1
</pre>
=={{header|PicoLisp}}==
<lang PicoLisp>(let Freq NIL
|