Created
September 2, 2024 16:32
-
-
Save tanvirstreame/66a24cc09d60eda9257533a2c846139d to your computer and use it in GitHub Desktop.
airwrk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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