Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3d130d

Browse files
committed
submit assignement
1 parent 7f657dd commit f3d130d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

cachematrix.R

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7+
inverse <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
inverse <<- NULL
11+
}
12+
get <- function() x
13+
setInverse <- function(inverseMatrix) inverse <<- inverseMatrix
14+
getInverse <- function() inverse
15+
list(set = set, get = get,
16+
setInverse = setInverse,
17+
getInverse = getInverse)
718

819
}
920

1021

1122
## Write a short comment describing this function
1223

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

0 commit comments

Comments
 (0)