File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# # Write a short comment describing this function
5
5
6
+ # # TODO:
7
+ # write guard clause against x != matrix
8
+ # fix indentation to 4
6
9
makeCacheMatrix <- function (x = matrix ()) {
7
-
10
+ inverse <- NULL
11
+ set <- function (y ) {
12
+ x <<- y
13
+ inverse <<- NULL
14
+ }
15
+ get <- function () x
16
+ setInverse <- function (inverseMatrix ) inverse <<- inverseMatrix
17
+ getInverse <- function () inverse
18
+ list (set = set , get = get ,
19
+ setInverse = setInverse ,
20
+ getInverse = getInverse )
8
21
}
9
22
10
23
11
24
# # Write a short comment describing this function
12
25
13
26
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
27
+ # # Return a matrix that is the inverse of 'x'
28
+
29
+ inverse <- x $ getInverse()
30
+ if (! is.null(inverse )) {
31
+ message(" getting cached inverse matrix" )
32
+ return (inverse )
33
+ }
34
+
35
+ data <- x $ get()
36
+ inverse <- solve(data , ... )
37
+ x $ setInverse(inverse )
38
+ inverse
15
39
}
You can’t perform that action at this time.
0 commit comments