Skip to content

Commit e12b2c1

Browse files
authored
Merge pull request #132 from MannyP31/manny
Added some more js programs
2 parents 3b10a70 + 1169475 commit e12b2c1

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
process.stdin.resume();
4+
process.stdin.setEncoding('utf-8');
5+
6+
let inputString = '';
7+
let currentLine = 0;
8+
9+
process.stdin.on('data', inputStdin => {
10+
inputString += inputStdin;
11+
});
12+
13+
process.stdin.on('end', _ => {
14+
inputString = inputString.trim().split('\n').map(string => {
15+
return string.trim();
16+
});
17+
18+
main();
19+
});
20+
21+
function readLine() {
22+
return inputString[currentLine++];
23+
}
24+
25+
/*
26+
* Modify and return the array so that all even elements are doubled and all odd elements are tripled.
27+
*
28+
* Parameter(s):
29+
* nums: An array of numbers.
30+
*/
31+
function modifyArray(nums) {
32+
var something=function(n){
33+
if(n%2==0)
34+
return n*2;
35+
else
36+
return n*3;
37+
38+
}
39+
var newArray=nums.map(something);
40+
return newArray;
41+
}
42+
43+
44+
function main() {
45+
const n = +(readLine());
46+
const a = readLine().split(' ').map(Number);
47+
48+
console.log(modifyArray(a).toString().split(',').join(' '));
49+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
process.stdin.resume();
4+
process.stdin.setEncoding('utf-8');
5+
6+
let inputString = '';
7+
let currentLine = 0;
8+
9+
process.stdin.on('data', inputStdin => {
10+
inputString += inputStdin;
11+
});
12+
13+
process.stdin.on('end', _ => {
14+
inputString = inputString.trim().split('\n').map(string => {
15+
return string.trim();
16+
});
17+
18+
main();
19+
});
20+
21+
function readLine() {
22+
return inputString[currentLine++];
23+
}
24+
25+
function getMaxLessThanK(n,k)
26+
{
27+
let max=0
28+
for(let i=1;i<n;i++)
29+
for(let j=i+1;j<=n;j++)
30+
{
31+
let and=i&j
32+
33+
if(and<k && and>max)
34+
max=and
35+
}
36+
return max
37+
}
38+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Rectangle {
2+
constructor(w, h) {
3+
this.w = w;
4+
this.h = h;
5+
}
6+
}
7+
8+
/*
9+
* Write code that adds an 'area' method to the Rectangle class' prototype
10+
*/
11+
Rectangle.prototype.area= function(){
12+
return this.w * this.h;
13+
}
14+
/*
15+
* Create a Square class that inherits from Rectangle and implement its class constructor
16+
*/
17+
//inherit from rectangle
18+
class Square extends Rectangle {
19+
//create Square constructor
20+
constructor (a){
21+
//call constructor from Rectangle class and insert value
22+
super (a,a);
23+
}
24+
}

0 commit comments

Comments
 (0)