PeculiarJS challenge

I’ve come across a weird but very interesting coding challenge:

In short, you call a function with a mal-formed argument, and you’re supposed to extract the string within. Example:

// should return "Bazinga"

Problem is that merely calling the function throws a syntax error. I’ve been scratching my head for a while over this, I find no way to at least catch the error so I can do something inside the function.

Does anyone have a hint (without completely giving it away)?

this is a weird one, also because the functions are not actually called with those values, but with the arrays containing correctly comma separated elements

// actual || expected
const f = getValue;
const tests = [
		[f([[[[[[[[[[[["Bazinga"]]]]]]]]]]]]), "Bazinga"],
		[f([[], [], [[[[[[], ["God what is happening..."]]]]]]]), "God what is happening..."],
		[f([[[[[[[[[[[]]]]]]]]]]]), "What... why did you make this?"],
		[f([[],[],[],[],[],[],[],[[],[],[[[[[[[["I have no idea what i'm doing"]]]]]]]]]]),"I have no idea what i'm doing"],
		[f([[[[[[[[[[[[]]]]], "I'm not gonna lose."]]]]]]]), "I'm not gonna lose.", "Yeah, it can be outside of it too lmao."]
for (let args of tests) {

So I imagine it would be a version of the Steamroll Array challenge in the freecodecamp curriculum

Hm yes, I just realised that they’re not actually calling the function, so you can only work in their editor. Which makes it a little :expressionless:
I think JSON.stringify-ing the argument and throwing some regex at it should solve it.

copy the tests and work somewhere else :smiley:

Ha I didn’t even think of that, thanks! Also just learned that Array.flat() takes an optional argument, like, Infinity (which makes the Steamroll challenge a little obsolete but I assume it was created before .flat() was a thing).

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