Skip to content

Commit 4296049

Browse files
committed
Add implementation to stub
1 parent 7f657dd commit 4296049

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

cachematrix.R

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
inv <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
inv <<- NULL
11+
}
12+
get <- function() x
13+
setinv <- function(val) inv <<- val
14+
getinv <- function() inv
15+
list(set = set,
16+
get = get,
17+
setinv = setinv,
18+
getinv = getinv)
819
}
920

1021

11-
## Write a short comment describing this function
22+
## Return a matrix that is the inverse of 'x'
1223

1324
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
25+
inv <- x$getinv()
26+
if(!is.null(inv)) {
27+
message("getting cached data")
28+
return(inv)
29+
}
30+
data <- x$get()
31+
inv <- solve(data, ...)
32+
x$setinv(inv)
33+
inv
1534
}

0 commit comments

Comments
 (0)