by the way here is my "amazing" solution for this question :) const uniqueArr = arr.map((subArr) => [...new Set([...subArr])]).flat(Infinity); const output = []; for (let i = 0; i < uniqueArr.length; i++) { if ( ![...uniqueArr.slice(0, i), ...uniqueArr.slice(i + 1)].includes( uniqueArr[i] ) ) { output.push(uniqueArr[i]); } } console.log(output);
Would this be a good solve? function findUnique(arr) { let allArrs = []; for (let i = 0; i < arr.length; i++) { allArrs = allArrs.concat(arr[i]); } console.log([...new Set(allArrs)]); } findUnique(words);
This should work in python def uniqueWords(wordsList): hashMap = {} counter = 0 for words in wordsList: for idx in range(len(words)): currentWord = words[idx] if currentWord not in hashMap: hashMap[currentWord] = counter else: if hashMap[currentWord] != counter: del hashMap[currentWord] counter += 1 return list(hashMap.keys()) print(uniqueWords([["hello", "goodbye", "morning", "hello"], ["goodbye", "night"]])) Should return ['hello', 'morning', 'night']
Thanks for your effort Justin
what is the name of this extention, when he typing, we saw somthing in front of that line. plz let me know.
by the way here is my "amazing" solution for this question :)
const uniqueArr = arr.map((subArr) => [...new Set([...subArr])]).flat(Infinity);
const output = [];
for (let i = 0; i < uniqueArr.length; i++) {
if (
![...uniqueArr.slice(0, i), ...uniqueArr.slice(i + 1)].includes(
uniqueArr[i]
)
) {
output.push(uniqueArr[i]);
}
}
console.log(output);
Would this be a good solve?
function findUnique(arr) {
let allArrs = [];
for (let i = 0; i < arr.length; i++) {
allArrs = allArrs.concat(arr[i]);
}
console.log([...new Set(allArrs)]);
}
findUnique(words);
Thanks for these videos.
Glad you like them!
This should work in python
def uniqueWords(wordsList):
hashMap = {}
counter = 0
for words in wordsList:
for idx in range(len(words)):
currentWord = words[idx]
if currentWord not in hashMap:
hashMap[currentWord] = counter
else:
if hashMap[currentWord] != counter:
del hashMap[currentWord]
counter += 1
return list(hashMap.keys())
print(uniqueWords([["hello", "goodbye", "morning", "hello"], ["goodbye", "night"]]))
Should return ['hello', 'morning', 'night']
function uniqueWords(arr) {
const obj = new Map();
const result = [];
for (let i = 0; i < arr.length; i++) {
const removeDuplicate = [...new Set(arr[i])];
removeDuplicate.forEach((word) => {
if (obj.has(word)) {
obj.set(word, obj.get(word) + 1);
} else {
obj.set(word, 1);
}
});
}
for (let [word, count] of obj) {
if (count === 1) {
result.push(word);
}
}
return result;
}
const uniqueWords = arrayOfArrays.reduce(folder, [])
const folder = (met, next) =>
( met.filter(e => !next.includes(e))
).concat([... new Set(next)].filter(e => !met.includes(e)))
Awesome! 👏🏻
const returnSingleAppearance = (arr) => {
const unique = [];
arr.forEach((strArray) =>
strArray.forEach((string) => {
const index = unique.indexOf(string);
index >= 0 ? unique.splice(index, 1) : unique.push(string);
})
);
return unique;
};