Skip to content

Commit 9d988c1

Browse files
committed
Finish cacheSolve function().
1 parent c94a872 commit 9d988c1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cachematrix.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ makeCacheMatrix <- function(x = matrix()) {
2929
## function.
3030

3131
cacheSolve <- function(x, ...) {
32-
## Return a matrix that is the inverse of 'x'
32+
## Search for inverse value in cache
33+
m <- x$getinverse()
34+
if(!is.null(m)) {
35+
## Cached value is found
36+
message("Retrieve from cache...")
37+
return m
38+
}
39+
data <- x$get()
40+
m <- solve(data, ...)
41+
x$setinverse(m)
42+
m
3343
}

0 commit comments

Comments
 (0)