Skip to content

Commit 2ed3f87

Browse files
committed
Added comments
1 parent 4925437 commit 2ed3f87

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cachematrix.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
## functions do
33

44
## Write a short comment describing this function
5-
5+
## This function caches x and solve (inverse matrix) and return a list of functions which
6+
## let get or set them
67
makeCacheMatrix <- function(x = matrix()) {
78
s <- NULL
89
set <- function(y) {
@@ -19,16 +20,24 @@ makeCacheMatrix <- function(x = matrix()) {
1920

2021

2122
## Write a short comment describing this function
22-
23+
## This function gets solve (inverse matrix). If it is not null return solve cached,
24+
## otherwise, get data (x), solve it, save it and return it
2325
cacheSolve <- function(x, ...) {
24-
## Return a matrix that is the solve (inverse) of 'x'
26+
## Return a matrix that is the solve (inverse) of 'x'
27+
28+
## Get cached solve (inverse matrix)
2529
s <- x$getsolve()
30+
## Return cached solve in case it is not null
2631
if(!is.null(s)) {
2732
message("getting cached data")
2833
return(s)
2934
}
35+
## otherwise, get data (x)
3036
data <- x$get()
37+
## solve (inverse matrix) data (x)
3138
s <- solve(data, ...)
39+
## save/store calculated s (inverse matrix)
3240
x$setsolve(s)
41+
## return calculated s (inverse matrix)
3342
s
3443
}

0 commit comments

Comments
 (0)