Skip to content

Commit c070743

Browse files
author
Adrian Quek
committed
Added comments. Didn't think they were necessary, but noticed they were part of the assessment. Oh well.
1 parent de562b0 commit c070743

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cachematrix.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7+
# returns a list of functions for:
8+
# - setting the matrix x
9+
# - getting the matrix x
10+
# - setting the inverse of the matrix x (s)
11+
# - getting the inverse of the matrix x
712
s <- NULL
813
set <- function(y) {
914
x <<- y
@@ -24,10 +29,12 @@ makeCacheMatrix <- function(x = matrix()) {
2429
cacheSolve <- function(x, ...) {
2530
## Return a matrix that is the inverse of 'x'
2631
s <- x$getinverse()
32+
# return cached inverse if it exists
2733
if(!is.null(s)){
2834
message("getting cached inverse")
2935
return(s)
3036
}
37+
# otherwise call solve to get the inverse and set it
3138
data <- x$get()
3239
s <- solve(data, ...)
3340
x$setinverse(s)

0 commit comments

Comments
 (0)