This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
from functools import reduce | |
def product(fracs): | |
t = reduce(lambda x, y : x * y, fracs) | |
return t.numerator, t.denominator | |
if __name__ == '__main__': | |
fracs = [] | |
for _ in range(int(input())): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processData(input) { | |
//Enter your code here | |
input = input.split('\n') | |
for(let i=1;i<input.length;i++){ | |
var splitWord = input[i].split(''); | |
var even = ''; | |
var odd = ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sides(literals, ...expressions) { | |
const [a,p] = expressions; | |
const root = Math.sqrt((p*p)-(16*a)); | |
const s1 = (p+root)/4; | |
const s2 = (p-root)/4; | |
return ([s2,s1]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle { | |
constructor(w, h) { | |
this.w = w; | |
this.h = h; | |
} | |
} | |
Rectangle.prototype.area = function () { | |
return this.w * this.h; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function modifyArray(nums) { | |
// iterate through the array | |
for(let i=0;i<nums.length;i++) { | |
// all even elements are doubled | |
if(nums[i] % 2 == 0){ | |
nums[i]*=2; | |
// all odd elements are tripled | |
}else{ | |
nums[i]*=3; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Complete the Rectangle function | |
*/ | |
function Rectangle(a, b) { | |
this.length = a; | |
this.width = b; | |
this.perimeter = 2 * (this.length + this.width); | |
this.area = this.length * this.width; | |
} | |
const rec = new Rectangle(4,5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCount(objects) { | |
for (let p in objects) { | |
return objects.filter(item => item.x == item.y).length; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
class Polygon{ | |
constructor(sides){ | |
this.sides = sides; | |
this.perimeter = this.perimeter; | |
} | |
perimeter() { | |
let sum = 0; | |
for(let i =0;i<this.sides.length;i++) { | |
sum = sum + this.sides[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverseString(s) { | |
try { | |
console.log(s.split("").reverse().join("")) | |
} catch (e) { | |
console.log(e.message); | |
console.log(s); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPositive(a) { | |
if (a == 0) { | |
throw new Error("Zero Error"); | |
} | |
if (a < 0) { | |
throw new Error("Negative Error"); | |
} | |
return 'YES'; | |
} | |
console.log(isPositive(-10)) |