Skip to content

Ahmad's Underpants#15

Open
AFord504 wants to merge 3 commits intoOperationSpark:masterfrom
AFord504:master
Open

Ahmad's Underpants#15
AFord504 wants to merge 3 commits intoOperationSpark:masterfrom
AFord504:master

Conversation

@AFord504
Copy link
Copy Markdown

@AFord504 AFord504 commented Sep 2, 2025

No description provided.

Copy link
Copy Markdown

@gregthompson27 gregthompson27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some food for thought on your code

Comment thread underpants.js
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AFord504 is there a way you could implement the native .slice method to complete this without using a loop?

Comment thread underpants.js
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above - how might you implement the native .slice method to to solve this part of _.last()?

Comment thread underpants.js
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))
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread underpants.js
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants