Skip to content

Instantly share code, notes, and snippets.

@tanvirstreame
Created September 2, 2024 16:32
Show Gist options
  • Save tanvirstreame/66a24cc09d60eda9257533a2c846139d to your computer and use it in GitHub Desktop.
Save tanvirstreame/66a24cc09d60eda9257533a2c846139d to your computer and use it in GitHub Desktop.
airwrk
function repeatDigitUntilOne(num) {
while (num > 9) {
num = num.toString().split('').reduce((sum, digit) => parseInt(sum) + parseInt(digit), 0)
}
return num;
}
console.log(repeatDigitUntilOne(38))
console.log(repeatDigitUntilOne(0))
function isDuplicate(nums) {
const unique = {};
let hasDuplicate = false
nums.forEach(num => {
if (unique[num]) {
unique[num] += 1;
}
else {
unique[num] = 1
}
});
Object.keys(unique).forEach(each => {
if (unique[each] > 1) {
hasDuplicate = true
return
}
})
return hasDuplicate
}
console.log(isDuplicate([1, 2, 3, 4]))
console.log(isDuplicate([1, 2, 3, 1]))
function reverseVowel(string) {
let vowel = ['a', 'e', 'i', 'o', 'u'];
const trackVowelPosition = [];
const strArr = string.split('');
let vowelArr = [];
let j = 0;
for (let i = 0; i < strArr.length; i++) {
if (vowel.includes(strArr[i].toLowerCase())) {
trackVowelPosition.push(i);
vowelArr.push(strArr[i]);
}
}
vowelArr.reverse()
trackVowelPosition.forEach(eachPosition => {
strArr[eachPosition] = vowelArr[j];
j++;
})
return strArr.join('')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment