Bridget Kacprzyk
Bridget Kacprzyk

Reputation: 27

What am I missing? Lambda Challenge

I'm trying to do the Lambda challenge and the output is what its asking but its still not correct?

The problem is: "Modify the function to transform the given string into an array where each character in the array is in the same index as it was in the string, and return it."

function convertStringToArray(s) {
var output = Array.from("hello");
return output;
}

/* Do not modify code below this line */

const exampleString = 'hello';
const stringAsArray = convertStringToArray(exampleString);

console.log(stringAsArray, '<-- should be ["h", "e", "l", "l", "o"]');

Output

["h", "e", "l", "l", "o"] <-- should be ["h", "e", "l", "l", "o"]

I did exactly what it wanted so why am I stuck?

Upvotes: 0

Views: 713

Answers (1)

Shadow
Shadow

Reputation: 9427

Your code takes an argument of s - which it ignores.

I highly suspect that the lambda challenge is passing different values to your function (only using "hello" as an example) and your code is failing because it only ever returns ["h", "e", "l", "l", "o"] even when s is "world".

Try using s instead of "hello" on the first line of your function.

Upvotes: 3

Related Questions