File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,20 @@ makeCacheMatrix <- function(x = matrix()) {
24
24
# # If the object is not stored in cached it is created and set to cached and retuned to calling context.
25
25
cacheSolve <- function (x , ... )
26
26
{
27
- # # Get the inverse value of 'x'
28
- invValX <- x $ getinverse()
29
- if (! is.null(invValX ))
30
- {
31
- message(" The cached value is returned." )
32
- return (invValX )
33
- } else {
34
- invValX <- solve(x $ get())
27
+ # # Get the inverse value of 'x' if any
28
+ invValX <- x $ getinverse()
29
+
30
+ # # is there any object in cache?
31
+ if (! is.null(invValX ))
32
+ {
33
+ message(" The cached value is returned." )
34
+ return (invValX )
35
+ }
36
+
37
+ # # Cache is empty, calculate the value and store it in cache
38
+ invValX <- solve(x $ get())
39
+ # set the object into cache
35
40
x $ setinverse(invValX )
36
- }
37
41
38
- return (invValX )
42
+ return (invValX )
39
43
}
You can’t perform that action at this time.
0 commit comments