Were some important methods mentioned in the lessons?

I proceeded to section " Basic Algorithm Scripting" and I’m a little confused. I look through the solutions of some tasks, and there are methods that were not covered in the previous sections: split, filter, reverse. And there was no link to a third-party resource. Am I missing something? Help.

Generally speaking, if alternative solutions contain methods that were not mentioned previously in the curriculum, the exercise can likely be solved without it as well.

These methods are certainly worth looking up, since they are common and make your life easier. The quasi-official go to site it Mozilla Developer Network (mdn). You can easily google these methods with “mdn” or “javascript”.

On the left side of these pages you can see lists of the array and string methods:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

w3schools for example has also lists (left side) with examples and descriptions:
https://www.w3schools.com/jsref/jsref_obj_array.asp

https://www.w3schools.com/jsref/jsref_obj_string.asp

You can find a lot more resources / videos etc. though…

1 Like

I also thought so, until I got to the task that cannot be solved without a method split


Thanks for the links! I’ll study other resources in parallel. Although I planned to move sequentially.

I guess I hurried with the statement that only split. This task can be solved using regexs. I haven’t figured out how exactly yet…)

It can also be solved without arrays or regex.

1 Like

and yet… I don’t understand how to solve this problem without the split method :frowning:
If anyone knows, please share!

This would also give you an array of words:
let words = str.match(/\w+/g);

(Though using split() seems more intuitive…)

1 Like

How would you solve this without using a computer? I would start at the beginning and count the number of nonspace characters. Once I reach a space I’d save off the current word length. Then I’d move on to the next word. If the length of the next word is greater than any previous words, I’d save that off as the new longest word length. Repeat until end of string.

2 Likes

I solved this one a long time ago without using arrays. I sent you a direct message with a link to such a solution.

1 Like

Thank you all for the tips and examples!
It turns out that everything can be solved based on experience from the lessons. It’s good! I already thought there was a catch)
It’s all about logic and perseverance.

These are really interesting solutions, thanks! A solution without an array is not for my current level)) I postpone its analysis for future.

Hi,

I just finished this lesson and I got the same question as n0vum when a saw the other people’s solutions. Will we cover such methods (split, filter, map, etc) in future lessons? or should I go to MDN and other sites while doing the lessos?

Thank you!

PD: My solution with regex:

function findLongestWordLength(str) {
let regWords = /\s*\w+\s*/gi;
let regSpace = /^\s+|\s+$/;
let arr = str.match(regWords);
let word = “”;
let longestWord = “”;
for(let i = 0 ; i < arr.length; i++) {
word = arr[i].replace(regSpace, “”);
if (word.length > longestWord.length) longestWord = word;
}
return longestWord.length;
}

1 Like

They are covered in future lessons, but MDN is always a good resource.

this is the first time i am posting and i don’t really know how to use the spoiler tag.
spoiler be warned.

this is my code with the knowledge of what is taught so far.
this is my first draft, i know it can be polish A LOT but it work.

function findLongestWordLength(str) {

  let temp= [ ];

  let testRegx = /\w*[^\s]/gi;

  //console.log(str.match(testRegx));

  temp=[...str.match(testRegx)];

  console.log(temp);

  let result= 0;

  for(let i= 0; i< temp.length; i++){

    

    if( temp[i].length> result){

      result= temp[i].length;

    }

  }

  return result;

}

findLongestWordLength("The quick brown fox jumped over the lazy dog");
1 Like