javascript/matrix: First working solution