en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

Array Task Solution Clarification

Open BuddhaHead opened this issue 4 years ago • 2 comments

Data Types > Arrays > Tasks > Second Task 'Array operations.' https://javascript.info/array#tasks

Instruction 3 states:

"Replace the value in the middle by "Classics". Your code for finding the middle value should work for any arrays with odd length."

This specifies that we should replace the middle value, and that our code should work for any arrays with an odd length.

The solution provided does not include a condition, and will always replace a value in an array, regardless of it's length.

Consider adding:

if (styles.length % 2 !== 0) { styles[Math.floor(styles.length / 2)] = 'Classics' }

BuddhaHead avatar Jun 17 '21 12:06 BuddhaHead

my opinion I guess the "odd len" is just to avoid the hardcoded a[1]= the point is basic array methods

I'd replace "odd" by "any", I dont see the "even len ambiguity" as an issue here

joaquinelio avatar Jun 22 '21 21:06 joaquinelio

I'd replace "odd" by "any", I dont see the "even len ambiguity" as an issue here

That makes sense. I took the instructions in a "rules as written" way, but your interpretation is likely how it was intended.

BuddhaHead avatar Jun 23 '21 06:06 BuddhaHead