forked from AdamMomen/warmUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarmUp4.js
More file actions
53 lines (34 loc) · 994 Bytes
/
Copy pathwarmUp4.js
File metadata and controls
53 lines (34 loc) · 994 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
39
40
41
42
43
44
45
46
47
48
49
// 1-Write a function that takes a string as an input and returns the reverse of each letter
//followed by a number starting from zero(solve it using while loop).
// example: reverseStr('hello'); "o1l2l3e4h"
function reverseStr(str){
var i=0
var revStr=""
while (i<str.length){
revStr= revStr+str[str.length-1-i]+i;
i++
}
return revStr
}
// 2-write a function that takes array of strings and returns an array of the strings that have the same length
// example : ['hi','hello','welcome','hy'] == > ["hi","hy"]
var arr = ['hi','hello','welcome','hy'] //== > ["hi","hy"]
function equiLength(arr){
var arr2=[];
for (var i = 0; i < arr.length; i++) {
arr2.push(arr[i].length);
}
var newArr= []
for (var j = 0; j < arr2.length; j++) {
console.log("hi")
for (var i = 1; i < arr2.length; i++) {
if (arr2[j]===arr2[i]) {
newArr.push(arr[j])
newArr.push(arr[i])
}
}
arr.splice(j)
arr2.splice(j)
}
return newArr;
}