Skip to content

Conversation

petitkriket
Copy link


return avg / array.length
}

Choose a reason for hiding this comment

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

You could have done this part as well with a for loop, like this:

function averageWordLength(array) {
  if (array.length === 0) {
    return undefined;
  }
  var sumLetters = 0;
  for (var i = 0; i < array.length; i++) {
    sumLetters += array[i].length;
  }
  return sumLetters / array.length;
}


return newArray;
}

Choose a reason for hiding this comment

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

It was a good beginning. With a for loop, you would probably have done it till the end.
Here is the solution to do it with a for loop. Don't be afraid of it! ;)

function uniquifyArray(array) {
  var newArray = [];
  if (array.length === 0) {
    return undefined;
  }
  for (var i = 0; i < array.length; i++) {
    if (newArray.indexOf(array[i]) === -1) {
      newArray.push(array[i]);
    }
  }
  return newArray;
}

@ta-web-paris
Copy link

Well done! You understood the notions in the exercise. Keep going this way!

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.

2 participants