This should
(1) delete layer 2, save the doc with layer 1 as AI, undo delete,
(2) delete layer 1, save the doc with layer 2 as PDF and undo delete again.
If you want it the other way around, swap the layers' names.
(Replace "..." in the path in line 3 below with your destination.)
var layer1 = app.activeDocument.layers["Layer 1"];
var layer2 = app.activeDocument.layers["Layer 2"];
var file1 = new File("/C/Users/.../Desktop/yourFileName");
var PDF = new PDFSaveOptions;
layer2.remove();
app.activeDocument.saveAs(file1);
app.undo();
layer1.remove();
app.activeDocument.saveAs(file1, PDF);
app.undo();