Symmetric Difference stringify and replace

Symmetric Difference stringify and replace
0

#1

Hello i am doing Symmetric Difference and was thniking to use JSON.stringify on Arguments and then replace it with regEx but it didn’t work i am wondering why ?

var newArr= JSON.stringify(arguments); // "{'0':[1,2,3],'1':[5,2,1,4]}"
newArr= newArr.replace(/'[\d]\'/g,""); //it didn't delete the keys then i have another 
newArr= newArr.replace(/[{}:\[\]]/g, "");  //this one worked
//and then i wanted to use filter or somethink iwoul chainit  

I used another approach but i still wondering why it didn’t worked?


#2

Best is to put the arguments into an array and then do a reduce on that array.

var testAry = [];
	testAry = Array.from(arguments).reduce(someCallbackFunc);

#3

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#4

Sry but i’m not asking what is best but i asking why it doesn’t work with replace ? the keys with “”?
or why it is wrong in general what artefacts it can generat


#5

Maybe because of missing :


#6

it Works for Second Replace but it doesnt work for first where i want to replace “(stringified) object keys” with ‘’


#7

It looks like quotes in stringified JSON are double quotes.

Replace ' with " in your regex.