Algoritmo - verificar si un valor existe dentro de un arreglo

JavaScript Algorithm Array count if value exist inside the array

Algoritmos

Los Algoritmos son una serie de pasos lĆ³gicos a seguir para resolver un problema, tienen un inicio y un final, datos de entrada, procesos y datos de salida. Son la base para el desarrollo de software.

El proceso se lleva a cabo a travĆ©s de preguntas lĆ³gicas y ciclos repetitivos para realizar cĆ”lculos aritmĆ©ticos y entregar un resultado.


Video

SuscrĆ­bete



Exercise

Given an Integer arr, count how many elements x there are, such that x is also in arr. If there're duplicates in arr, count them separately.


Example 1

Input: arr = [1,2,3]
Output: 2

Explanation:

There are 2 such elements. 1 and 2 because 2 and 3 are also in the array.


Example 2

Input: arr = [1,1,3,3,5,5,7,7]
Output: 0

Explanation:

There's no such number because 2, 4, 6 or 8 is not present in the array.


Example 3

Input: arr = [1,3,2,3,5,0]
Output: 0

Explanation:

There's no such number because 2, 4, 6 or 8 is not present in the array.


Example 4

Input: arr = [1,1,2,2]
Output: 2

Explanation:

There are 2 such numbers, and 1 and 1 because 2 is in the array and duplicates are counted separately.


Example 5

Input: arr = [1,1,2]
Output: 2

Explanation:

There are 2 such numbers, and 1 and 1 because 2 is in the array and duplicates are counted separately.


Try the code in CodePen


See the Pen Untitled by Vladimir Salguero (@vladisalguero) on CodePen.