Repository navigation
Expand file tree
/
Copy pathstring.js
More file actions
132 lines (86 loc) · 2.44 KB
/
Copy pathstring.js
File metadata and controls
132 lines (86 loc) · 2.44 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
let username = "Adebayo";
// console.log(username.length);
// console.log(username.charAt(0));
// console.log(username.charAt(username.length-1));
//write a js code that will reverse a string
// hello => olleh
// mike => ekim
// for(let i=1; i<=5;i++){
// // console.log(i);
// }
// for(let i =5; i>0; i--){
// console.log(i);
// }
// function revString(str){
// let rev = "";
// for(let i=str.length-1; i>=0; i--){
// let charcter = str.charAt(i);
// rev += charcter;
// }
// rev = rev.replace(" ","");
// return rev;
// }
// console.log(revString("hello world"));
// split
// console.log(username.split(''));
//join
// const people =["black","white","brown"];
// console.log(people.join("-"));
// sdlc => requiremnet, anaysis, design,implementation, testing, deployemnet,documenatation, maintance
// write a program to output the winner between vowel and consaonet in a given string
// if there is no winner output draw
// aeoiu
// "hello" =>"consonant wins"
// "ebube"=>"vowel wins"
// "mike" => "draw";
function battle(str){
let vowel = 0;
let consonant = 0;
let info = "";
str = str.toLowerCase();
let vowels = ["a","e","i","o","u"];
for(let i =0; i<str.length; i++){
let chara = str.charAt(i);
if(vowels.includes(chara)){
vowel++;
}else{
consonant++;
}
}
if(vowel>consonant)
info = "vowel wins";
else if(consonant > vowel)
info = "Consonant wins";
else
info = "draw";
return info
}
// console.log(battle("mike"));
//write a function to return words in an array whose length is greater than a given length
// ["a","ab","abc"], 3 => []
// ["hello","world"], 1=>["hello","world"]
// ["ayagig","phone"],5 =>["ayagig"]
function wordGreater(str, len){
const greaterLen = [];
for(let i = 0; i<str.length; i++){
let wordLetter = str[i];
if(wordLetter.length > len)
greaterLen.push(wordLetter);
}
// for(let word of str){
// if(word.length > len) greaterLen.push(word);
// }
return greaterLen;
}
// console.log(wordGreater(["ayagig","phone"],5));
//write a function that will repeat the vowel in a given string the number of time facetor
// "hello", 2 =>heelloo
// "mike", 1 => mike,
// "aya", 4 => aaaayaaaa
// let letter = ""
// for(let i=0; i<5;i++){
// letter +="a";
// }
// console.log(letter);
let lett = "a";
console.log(lett.repeat(4));