nikomarow
BAN USER
const obj = {};
["geeks", "for", "geeks", "a", "portal", "to", "learn", "can", "be", "computer", "science", "zoom", "yup", "fire", "in", "be", "data", "geeks"].forEach(item => {
if(obj[item] === undefined) {
obj[item] = 1;
} else {
obj[item]++;
}
});
Object.entries(obj).sort((a, b) => a[1] - b[1]).slice(-2).reduce((arr, item) => {
arr.push(item[0]);
return arr;
}, []);
JavaScript
- nikomarow November 26, 2019function isPeriodic(str) {
f: for (let i = 0; i <= str.length / 2; i += 1) {
window.P = str.substring(0, i);
if (!window.P) {
continue;
}
for (let x = 0; x < str.length; x += window.P.length) {
const currentPattern = str.substr(x, window.P.length);
if (currentPattern !== window.P) {
break;
} else if (x + window.P.length === str.length) {
console.log('RESULT', window.P, str.length / window.P.length);
break f;
}
}
}
}
Open Chat in New Window
- nikomarow January 23, 2020