Freecodecamp: Challenge way to easy

Created on 29 Jul 2016  路  11Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Slasher Flick has an issue.
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36.
This challenge can be solved in one line of code. Is it intended that way? If yes than ok. If not, note that suggested method is actually a solution.

My code:


function slasher(arr, howMany) {
  // it doesn't always pay to be first
  var arr2 = arr.slice(howMany);
  return arr2;
}

slasher([1, 2, 3], 2);

help wanted

All 11 comments

I somewhat tend to agree, not sure if we should change the verbiage and add more tests though.
@erictleung thoughts?

@raisedadead I also somewhat agree that this is pretty easy. We could add in some constraints like filter out non-numbers and then start chopping off elements. It would up the challenge a little bit.

Perhaps splicing the removed elements back in at a different point of the array, which would then turn it from a slasher flick into a Frankenstein rip-off 馃槃

Or how about "create a new array by splicing the first n elements from the first argument into the second argument starting at the middle position," with two array arguments (perhaps all even-lengthed arrays for the second argument for simplicity).

If still too easy, require that the input arrays are not mutated.

This is a required challenge, we can have a fair amount of toughness, at least in increment of the previous

Here's a rough idea of a frankenSplice challenge, feedback appreciated!


// Use slice() and splice() to insert the elements of the first array into the second, starting at index n of the second array.
// Optional objective: Do not mutate the input arrays.

// Solution (with optional objective)
const frankenSplice = (arr1,arr2,n) => {
    let r = arr2.slice();
    for (let i = 0; i<arr1.length; i++){
        r.splice(n+i,0,arr1[i]);
    }
    return r;
};

a = [1,2,3];
b = ["c","d","e","f"];

frankenSplice(a,b,2); // [ 'c', 'd', 1, 2, 3, 'e', 'f' ]
console.log(a); // [ 1, 2, 3 ]
console.log(b); // [ 'c', 'd', 'e', 'f' ] // Input arrays remain intact

mutate maybe little tough on non-native speakers?

How about?

The input arrays should still remain the same

Oh yeah, this is not final language at all, just brainstorming about the requirements and difficulty of this potential challenge.

Is it feasible to have multiple tests check that various input arrays have not been changed by the function? Or does that make the test code overly complex?

I do think this is a good opportunity to reinforce that some array methods mutate arrays even outside the function scope, even if it's described in simpler language, and that requirement means users will have to use _both_ slice and splice to solve it fully.

Tests are basically asserts. So wecan have one assert check all the input arrays. not complex, but lengthy one. To be clear this one will need a assert.deepEqual to check the arrays and chain them with logical AND

Yup I agree to the second point as well

I do think this is a good opportunity to reinforce that some array methods mutate arrays even outside the function scope, even if it's described in simpler language, and that requirement means users will have to use both slice and splice to solve it fully.

Finally got my replacement working now that tails are (mostly) working in staging again! Writing the PR now..

BKinahan my code is equal to yours and it outputs everything as supposed and yet it tells me that the variables are changed... did you pass this with that code?

function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  var ans=arr2.slice();
  for(i=0;i<arr1.length;i++){
  ans.splice(n+i,0,arr1[i]);
  }
  console.log(ans);
  console.log(arr1);
  console.log(arr2);
  return ans;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

trashtalka3000 picture trashtalka3000  路  3Comments

DaphnisM picture DaphnisM  路  3Comments

raisedadead picture raisedadead  路  3Comments

MichaelLeeHobbs picture MichaelLeeHobbs  路  3Comments

EthanDavis picture EthanDavis  路  3Comments