0

I'm currently doing the following:

_.map(_.shuffle(myMapping), (item, index) => (
  <p>{item.title}</p>
))

How can I essentially duplicate myMapping so that myMapping = myMapping + myMapping?

I'm not trying to remove duplicate, I was the copy to be 2x in length.

2 Answers 2

2

Using lodash

var myMapping  = [1,2,3,4,5]
var myMappingPlus = _.flatten(
   _.map(myMapping, function(v) { return [v, v];});
 );

You map an element to an array and then flatten it.

Sign up to request clarification or add additional context in comments.

1 Comment

You can shuffle the whole thing _.shuffle(myMappingPlus) if you like.
0

The .concat() method concatenates arrays:

_.map(_.shuffle(myMapping.concat(myMapping)), (item, index) => (
  <p>{item.title}</p>
))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.