JSFiddle - React, Tailwind, and code Playground
HTML
<button data-bind="click: carregar">Carregar</button>
<button data-bind="click: organizar">Ordenar</button>
<button data-bind="click: media">Média</button>
<ul data-bind="foreach: numeros">
<li data-bind="text: numero"></li>
</ul>
JavaScript
var soma = 0
function ranum() {
this.numero = ko.observable(Math.floor(Math.random() * 101))
}
function numzac() {
var self = this
self.numeros = ko.observableArray([])
self.carregar = function() {
self.numeros.removeAll()
for (i = 0; i < 10; i++) {
self.numeros.push(new ranum())
}
console.log(self.numeros)
}
self.organizar = function() {
self.numeros.sort(function(a, b) {
return a.numero() - b.numero();
});
}
self.media = function() {
}
}
ko.applyBindings(new numzac())