JSFiddle - React, Tailwind, and code Playground
by Ronny
JavaScript
Array.prototype.isUnique = function(term, isCaseSensitive){
term = String(term);
if (!isCaseSensitive) term = term.toLowerCase();
var a = isCaseSensitive ? this : this.join().toLowerCase().split(',');
var isUnique = a.indexOf(term) === a.lastIndexOf(term);
// Terms that don't exist in the array will return true, as -1 === -1. Verify the term exist before using this method.
return isUnique;
};
var a = ['ronny','RONNY', 'rOnNy','Nir'];
var b = [2,4,65,2];
var c = [true, true, false];
var d = [null, undefined, null];
console.log('The following should be true:');
console.log( a.isUnique('Nir') );
console.log( b.isUnique(65) );
console.log( c.isUnique(false) );
console.log( d.isUnique(undefined) );
console.log( a.isUnique('RONNY', true) );
console.log('The following should be false:');
console.log( a.isUnique('ronny') );
console.log( b.isUnique(2) );
console.log( c.isUnique(true) );
console.log( d.isUnique(null) );