-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas7.js
More file actions
152 lines (85 loc) · 2.86 KB
/
as7.js
File metadata and controls
152 lines (85 loc) · 2.86 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 1. Input a String S, and check its length and if the length is greater than 4,
// truncate the input String and output the result -str = "Icecream"
// if( str.length > 4 ){
// console.log(str.slice(0,4)+"...")
// }
// else{
// console.log("bye")
// }
// 2. Input a String S with multiple words, and remove whitespaces and
// output the result -
// str1 = " Hii Boy"
// output = ""
// for(let i of str1){
// if(i.charCodeAt() !== 32){
// output +=i
// }
// }
// console.log(output)
// 3) Input a String S with two words, and replace first word with second word
// and display the result -
// str2 = "Hii Boy"
// output = 0
// for(let i in str2){
// if(str2[i].charCodeAt() === 32){
// output = i
// }
// }
// console.log(str2.slice(Number(output)+1,str2.length)+ " "+ str2.slice(0,output));
// 4)4. Input a String S with a word, and replace character “a” with “x” and
// display the result -
// str3 = "apple"
// const newString = str3.replace("a", "x");
// console.log(newString);
// 5 What string method can be used to convert string into array ?
// ---> Split method
// 6 What string method can be used to check the occurrence of a specified
// => indexOf()
// 7. How can you break a string to a newline in Javascript ?
// => we can use \n
//8. Write a Javascript function to test whether the first character of a string
// is lowercase.
// const test = (str) =>{
// if(str.charCodeAt(0) >= 97 && str.charCodeAt(0) <= 122 ){
// console.log(`First letter => ${(str[0])} is in lower case`)
// }else{
// console.log(`first character => ${(str[0])} is not a lowercase character`);
// }
// }
// test("Subham")
// test("ineuron")
// 9. Give a correct verdict to users input if he enters "yes", "YES","Yes" ,etc
// (any combination) using string methods. How will you handle that ?
// => In this case we convert all that to lowercase or uppercase.
// 10. Given a String S, achieve following tasks
// a) Convert the String into upper case.
// s = "Subham"
// S = s.toUpperCase();
// console.log(S)
// b) Convert only the first character to uppercase.
// s = "subham"
// S = s[0].toUpperCase() + s.slice(1,);
// console.log(S);
// c) Convert the String into lower case.
// s = "SUBHAM"
// S = s.toLowerCase();
// console.log(S);
// d) Break the string into two halves and swap them.
// s = "Subham"
// S = s.slice(0,Math.floor((s.lenght)/2))
// console.log(S);
// e) Count the repeating characters.
// s = "subhamma"
// count = 0
// for(let i = 0; i< s.length; i++){
// for(let j = i+1; j<s.length; j++){
// if (s[i] === s[j]){
// count+=1
// }
// }
// }
// console.log(`There is ${count} reapeating character.`)
// f) Reverse the string
// string = "subham"
// string = [...string].reverse().join("");
// console.log(string);