Skip to content

Instantly share code, notes, and snippets.

@AsifITk
Created November 11, 2021 11:18
Show Gist options
  • Save AsifITk/f08e7ea83866593ce1090b44ae97dbb5 to your computer and use it in GitHub Desktop.
Save AsifITk/f08e7ea83866593ce1090b44ae97dbb5 to your computer and use it in GitHub Desktop.
// isUniqueRepeated('aaaaa');
// ➞ true // because the character `a` is the single character which is repeated over the length of the array.
// isUniqueRepeated('aaabba');
// ➞ false // because there is not a single character which is repeated over the length of the array.
// isUniqueRepeated('');
// ➞ true // for empty strings return true.
// isUniqueRepeated('abcdef');
// ➞ false // because there is not a single character which is repeated over the length of the array.
function isUniqueRepeated(word){
let arr = word.split('');
let test = true;
for (let i=0; i<arr.length-1; i++){
if(arr[i]!=arr[i+1]){
test = false;
break;
}
}
return test;
}
// //filterUniqueRepeated(["aaaaaa", "bc", "d", "eeee", "xyz"])
// ➞ ["aaaaaa", "d", "eeee"]
// filterUniqueRepeated(["88", "999", "22", "545", "133"])
// ➞ ["88", "999", "22"]
// filterUniqueRepeated(["xxxxo", "oxo", "xox", "ooxxoo", "oxo"])
// ➞ []
function filterUniqueRepeated(arrr){
const result = arrr.filter(isUniqueRepeated);
return result;
}
console.log(filterUniqueRepeated(["88", "999", "22", "545", "133"]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment