# Basic Algorithm Scripting: how to remove an item properly from the object?

Dear freeCodeCampers,

I am struggling with this exercise: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence/

I commented out line 14, because it does work properly. My intention was to remove an item from the array based on str [i], but it does not work properly.

Wow. Seems to me you might want to rethink your strategy. Youâ€™re going through letter-by-letter, when you may not really need to. You know a couple of things:

1. youâ€™ll get a string of words, possibly of mixed case.
2. for EACH word, the first letter should be upper case.
3. for EACH word, the rest of the letters should be lower case.
4. you will return a string, containing each word with the above modifications.

Does this indicate something? Perhaps splitting the string into an array of words, then doing something with each word individually?

Another strategy would be to split the array into words, then for each word process them separately.

2 Likes

Another suggestion? When youâ€™re dealing with pure javascript (rather than JS and HTML and/or CSS), you may find something like repl.it is more suitable. You can choose an pure-JS environment, and itâ€™ll set you up with an editor and a displayed console.

As this is not a final challenge, I donâ€™t mind sharing the code I put together for this, if you think it might help. Take a look at this repl.

1 Like
• Start by making the whole string lowercase, easier to compare.
• Convert the string to an array by using split, this will make you be able to loop each word in the string.
• Use console.log() here and there, to check if you get the result you intend to before moving further with the code.
• .map() would be useful here.
1 Like

Thank you. I will try this way also.

This is an interesting approach. I will try to write the code based on your steps.

Hereâ€™s a strategy. Youâ€™ll want to break a sentence into an array of words and go over each word. You want to make sure the first letter is uppercase and the rest of the letters are not.

Hint: String.prototype.split() and String.prototype.substring()

1 Like

`String.replace()` is also a fun option.

2 Likes