-1

I was doing some algorithms on edabit.com and I came across this question.

 *Create a function that takes an array. This array will contain numbers represented as strings.*

 *Your function should split this array into two new arrays. The first array should contain only even 
  numbers. The second only odd. Then, wrap these two arrays in one main array and return it.*

 *Return an empty array if there are no even numbers, or odd.*

I solved with a simple method it but when I looked into the solutions section I found someone solve it like this :

const cleanUpArray=arr =>{ var arr1=[],arr2=[];
arr.map(a=>a%2===0?arr1.push(+a):arr2.push(+a));
return [arr1,arr2];}

what does the plus sign do?, when I removed it, I got all strings in the arrays.

  • @CertainPerformance I think [this](https://stackoverflow.com/questions/6682997/what-is-the-purpose-of-a-plus-symbol-before-a-variable) is a better dupe? I've added it to the list... – Nick May 02 '21 at 05:07

0 Answers0