-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevolutioninterview.js
More file actions
49 lines (36 loc) · 972 Bytes
/
Copy pathevolutioninterview.js
File metadata and controls
49 lines (36 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Input: "Hello, I am a string. Add your creativity here"
Output : {
length: 46,
vowelsCount: 15,
duplicates: [
'l', ' ', 'a', 'i',
'd', 'o', 'r', 'e',
't', 'y', 'h'
],
reverse: 'ereh ytivitaerc ruoy ddA .gnirts a ma I ,olleH'
}
const str = "Hello, I am a string. Add your creativity here";
console.log('Length of string :',str.length)
let splitArr = str.toLowerCase().split('');
let flag = 0;
for(let x of splitArr){
if(x === 'a' || x=== 'e' || x=== 'i'|| x === 'o' || x==='u'){
flag++;
}
}
console.log('Length of vowels :',flag)
console.log(str.split(''))
let newStr = str.split('')
// let newSet = new Set(str.split(''));
// console.log(newSet)
let arr1 = []
for(let i=0;i<newStr.length-1;i++){
for(let j=i+1;j<newStr.length;j++){
if(newStr[i]===newStr[j]){
arr1.push(newStr[i])
}
}
}
console.log('duplicates:',arr1)
console.log(new Set(arr1))
console.log(Array.from(new Set(arr1)))