Unique Properties
Unique Properties is when in a string every letter is unique if they are all different unique then it is true and returns all unique values of an array if not like the second example if there are duplicates than it returns only unique values ___
##For Example
a,b,c,d,e => abcde
a,b,c,d,a => abcd##
let arr = [
{
letter:"a"
},
{
letter:"b"
},
{
letter:"c"
},
{
letter:"a"
}
];
function getUnique(arr){
let tempArr = arr.map(item => item.letter);
return [... new Set(tempArr)];
}
we return [a,b,c]
function getUnique(arr){
First we create a function called getUnique and pass an argument called arr.
let tempArr = arr.map(item => item.letter);
We create temporary variable array tempArr and use the map method where we map through the arr and we say whenever which and every item we would want to return the letter value into item.letters
return [… new Set(tempArr)];
Then for single values we use the data structure Set and we return spread operator to spread every new addition and substiction of unique data provided with new Set and inside the parathesis we put the temporary variable tempArr
comments powered by Disqus