js数组如何查找消失数字

const fs = require('fs');
function findMissingNumbersUsingBooleanArray(arr, n) {
          const presenceMarker = new Array(n).fill(false);
          for (let num of arr) {
                    if (num >= 1 && num <= n) {
                              presenceMarker[num - 1] = true;
                    }
          }
          const missingNumbers = [];
          for (let i = 0; i < presenceMarker.length; i++) {
                    if (!presenceMarker[i]) {
                              missingNumbers.push(i + 1);
                    }
          }

          return missingNumbers;
}

function saveToFile(filename, data) {
          fs.writeFile(filename, data.join('\n'), err => {
                    if (err) throw err;
                    console.log(`The file has been saved as ${filename}`);
          });
}
const n = 30;
const arr = [1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23]
const missingNumbers = findMissingNumbersUsingBooleanArray(arr, n);
saveToFile('missing_numbers.txt', missingNumbers);