Open
Conversation
gregthompson27
left a comment
There was a problem hiding this comment.
Just some food for thought on your code
Comment on lines
+91
to
+98
| // Adds first 'num' values to items | ||
| var items = []; | ||
| for (var i = 0; i < num; i++) { | ||
| items.push(arr[i]); | ||
| } | ||
|
|
||
| // Returns new array | ||
| return items; |
There was a problem hiding this comment.
@AFord504 is there a way you could implement the native .slice method to complete this without using a loop?
Comment on lines
+128
to
+135
| // Adds last 'num' values to items | ||
| var items = []; | ||
| for (var i = arr.length - num; i < arr.length; i++) { | ||
| items.push(arr[i]) | ||
| } | ||
|
|
||
| // Returns new array | ||
| return items; |
There was a problem hiding this comment.
Same question as above - how might you implement the native .slice method to to solve this part of _.last()?
Comment on lines
+331
to
+337
| if (Array.isArray(coll)) { | ||
| _.each(coll, (element, index, array) => output.push(func(element, index, array))); | ||
| } else if (_.typeOf(coll) === 'object') { | ||
| for (var [key, value] of Object.entries(coll)) { | ||
| output.push(func(value, key, coll)) | ||
| } | ||
| } |
There was a problem hiding this comment.
Is the if statement here necessary - didn't you write some similar logic already inside your _.each method to check for object literals vs. arrays?
Comment on lines
+355
to
+366
| var output = _.map(arr, function (element) { | ||
| // Iterates over objects in 'arr' | ||
| for (var [key, value] of Object.entries(element)) { | ||
| // Finds 'prop' and returns its value | ||
| var val; | ||
| key === prop ? val = value : null; | ||
| return val; | ||
| } | ||
| }); | ||
|
|
||
| // Returns a new array | ||
| return output; |
There was a problem hiding this comment.
Suggested change
| var output = _.map(arr, function (element) { | |
| // Iterates over objects in 'arr' | |
| for (var [key, value] of Object.entries(element)) { | |
| // Finds 'prop' and returns its value | |
| var val; | |
| key === prop ? val = value : null; | |
| return val; | |
| } | |
| }); | |
| // Returns a new array | |
| return output; | |
| return _.map(arr, function (element) { | |
| // Iterates over objects in 'arr' | |
| for (var [key, value] of Object.entries(element)) { | |
| // Finds 'prop' and returns its value | |
| var val; | |
| key === prop ? val = value : null; | |
| return val; | |
| } | |
| }); |
It is possible, and is not a bad coding practice at all, to just return a map like this directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.