Mutations in Basic Algorithm Scripting

I really really have been stinking at writing code, I think my main flaw is that I don’t understand all the different methods and how they connect. I’ll write a good chunk of code that has loose ideas, but then I don’t know who to wrap it up nicely. I’m probably just thinking of this the wrong, but what would be the best recommendation for me here?

  **Your code so far**

function mutation(arr) {
for (let i = 0; i > arr.length; i++) {
toLowerCase();
arr.indexOf(arr);
return arr; 
}
}

mutation(["hello", "hey"]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62

Challenge: Mutations

Link to the challenge:

I think adding some more comments in your code would help us understand what you are trying to do with this.

function mutation(arr) {
  for (let i = 0; i > arr.length; i++) {
    // What is being converted to lower case?
    toLowerCase();
    // getting the index of the array in the array?
    arr.indexOf(arr);
    // a return statement immediately stops everything, so
    //  you probably don't want one inside of this loop
    return arr; 
  }
}

mutation(["hello", "hey"]);

I don’t see enough to understand what you plan is.

great, I’ll try
Thank you

ill contribute to the response pointing out weak points in your code.
toLowerCase() is a string method. This means it should be attached to a string. For example "This is a string".toLowerCase(). Ofc, the string can be a variable which holds a string value text.toLowerCase().
The return statement within a function stops its execution and returns the value you attach to the return. In your case you return the arr value. The problem is, when you place it within a loop(for example for loop, such is in your case), it will stop the looping too, as soon as return comes in place. Even if you meant the loop to iterate for the length of the array, it will only loop until it hit return(in the initial iteration in your case).

Guess I really don’t have one lol? My way of thinking is that I needed to think about all the different methods I’m going to need to make this work, I’m definitely going to need the indexOf() method to sift through the string, however I can’t do that without the letters all having the same case as it is case sensitive. Obviously this a garbled nonsense loop that doesn’t mean much of anything, but I don’t know how to get past that.

I didn’t even know that if you had the return statement in a loop that it does that, so that’s very good to know thank you! Maybe I’m just confused as to what exactly would work best to link up the toLowerCase() to the arr in the function.

You need a plan before you pick syntax. How would you do this task with pencil and paper?

I mean this is the very loose idea of where I was going, I have a general idea that I want to pick through each of the words and then filter out any words that have invalid characters. Obviously none of this makes sense just because I don’t know what methods to use for it. I’m hoping my thought process isn’t more convoluted than it needs to be.


function mutation(arr) {
for (let i = 0; i > arr.length; i++) {
toLowerCase();
split();
//1: splits each character of the string into seperate elements so that the indexOf() can find each letter of a word. 
}
return arr;
}

//2: reads through the returned array and looks for any missing characters 

arr.indexOf(arr) 




//3: calls back the function 

mutation(["hello", "hey"]);

It is too early to focus on syntax. You need an actual plan first. Again, how would you do this by hand without a computer, step by smallest step?

Ok well I’d probably figure out all of the areas of the algorithm that I’m going to need the most (I.E. break it down into chunks). Figure how to start and end the program, and what necessary steps are needed to get there.

What are those steps? Program? What program? A human accomplishing this task by hand doesn’t need a program, just a good list of steps.

I think I see what you’re getting at lol. Well I need to look for words that match in terms of having the same letters, trashing any that don’t have the same letters present right?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.