-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11i.html
More file actions
76 lines (73 loc) · 2.31 KB
/
11i.html
File metadata and controls
76 lines (73 loc) · 2.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array num inc</title>
</head>
<body>
<script>
function countWords(words) {
const result = {};
for (let i = 0; i < words.length; i++) {
const word = words[i];
// result[word] adds/accesses a property using whatever is
// saved inside the 'word' variable.
// If word = 'apple', result[word] will do result['apple']
// If word = 'grape', result[word] will do result['grape']
if (!result[word]) {
result[word] = 1;
} else {
result[word]++;
}
}
return console.log(result);
}
function minMax(nums){
let result={
min: nums[0],
max: nums[0]
};
//DOing in loop instead of math.min
for(let i=0;i<nums.length;i++){
if(result.min>nums[i]){
result.min=nums[i];
}
if(result.max<nums[i]){
result.max=nums[i];
}
}
console.log(`Min: ${result.min}, Max: ${result.max}`)
}
function countPositive(nums){
let temp=[];
for(let i=0;i<nums.length;i++){
if(nums[i]>0){
temp.push(nums[i])
}
}
return console.log(`Positive Numbers in this array is ${temp.length}`);
}
function addNum(array,num){
for(let i=0;i<array.length;i++){
array[i]+=num;
}
return console.log(array);
}
function addArrays(array1,array2){
let resulting_array=[];
for(let i1=0;i1<array1.length;i1++){
for(let i2=0;i2<array2.length;i2++){
resulting_array.push(array1[i1]+array2[i2])
}
}
return console.log(resulting_array);
}
countWords(['apple', 'grape', 'apple', 'apple']);
minMax([1,2,3,4,55,6,7,7,7,543,1,1])
countPositive([1,2,3,4,5,6,7,-1,0,-3,-3433])
addArrays([1,2],[222,334]);
addNum([1,2,3,2922,233],89);
</script>
</body>
</html>