# Finding two missing numbers that appears only once and twice respectively in JavaScript

JavascriptWeb DevelopmentFront End Technology

#### JavaScript for beginners

Best Seller

74 Lectures 10 hours

#### Modern Javascript for Beginners + Javascript Projects

Most Popular

112 Lectures 15 hours

#### The Complete Full-Stack JavaScript Course!

Best Seller

96 Lectures 24 hours

## Problem

We are required to write a JavaScript function that takes in an array in which all the numbers appear thrice except one which appears twice and one which appears only one. Our function should find and return these two numbers.

## Example

Following is the code −

Live Demo

const arr = [1, 1, 1, 2, 2, 3];
const findMissing = (arr = []) => {
let x = 0;
let y = 0;
for(let i = 0; i < arr.length; i++){
if(arr.filter(a => a === arr[i]).length === 2){
y = arr[i];
};
if(arr.filter(b => b === arr[i]).length === 1){
x = arr[i];
};
};
return [x, y];
};
console.log(findMissing(arr));

## Output

Following is the console output −

[3, 2]
Updated on 20-Apr-2021 07:22:59