swati-jagtap / javascript-practice

0 stars 0 forks source link

7.3.16--Write a functions which checks if all items are unique in the array. #76

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago

`

7.3.16--Write a functions which checks if all items are unique in the array.


function unique(arr)
{ 
    var a=arr.toString();    
    for(let i=0;i<arr.length;i++)
    {
        if(a.indexOf(arr[i])!=a.lastIndexOf(arr[i]))
        {
                 return `Array Items Are Not Unique`;
                 break;
        }
        else
        {
            return `All Items Are Unique`;
        }
    }
}
console.log(unique([1,4,2,1,9,6]));
console.log(unique([1,4,2,9,6]));
console.log(unique([1,"s",9,6]));`

output

image