Professional Documents
Culture Documents
Function Let Const Let If Let Const
Function Let Const Let If Let Const
let resultArr = [];
query.forEach(el => {
const wordToCheck = el.split('');
let anagram = 0;
dictionary.forEach(word => {
if (wordToCheck.length === word.length){
let coincidence = 0;
const wordArr = word.split('').sort();
wordToCheck.sort();
wordToCheck.forEach((value, i) => {
value === wordArr[i] ? coincidence++ : null;
})
coincidence === wordToCheck.length ? anagram++ : null
}
})
resultArr.push(anagram);
})
return resultArr;
}
function longestSubarray(arr) {
const withoutRep = new Set();
arr.forEach(el => {
withoutRep.add(el);
})
let coin;
let max;
withoutRep.forEach(el => {
max = 0;
coin = 0;
for (const number of arr) {
if (el === number || el + 1 === number || el - 1 === number){
coin++;
}
else {
break;
}
}
coin > max ? max = coin : null;
})
return max;
}