Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds javascript version( ES5 and ES6) for exiting formulas #244

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions algebra/permutations/javascript/permutation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ES5

function factorial(n) {
if (n === 0)
return 1;
else
return n * factorial(n - 1);
}

function permutation(n, r) {
return factorial(n) / factorial(n - r);
}

// ES6

let factorial = (n) => {
if (n === 0)
return 1;
else
return n * factorial(n - 1);
};

let permutation = (n, r) => factorial(n) / factorial(n - r);
37 changes: 37 additions & 0 deletions algebra/quadratic_formula/javascript/quadratic_formula.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ES5 way

function quadratic_formula(a, b, c) {

var discrimiant = b**2 - (4 * a * c);
if (discrimiant < 0) {
return "This equation does not have a real solution";
}
else if (discrimiant === 0) {
return (-b + Math.sqrt(discrimiant)) / 2 * a;
}
else {
var answers = {};
answers["solution_one"] = (-b + Math.sqrt(discrimiant)) / (2 * a);
answers["solution_two"] = (-b - Math.sqrt(discrimiant)) / (2 * a);
return answers;
}
}

// ES6 way

let quadratic_formula = (a, b, c) => {

let discrimiant = b**2 - (4 * a * c);
if (discrimiant < 0) {
return "This equation does not have a real solution";
}
else if (discrimiant === 0) {
return (-b + Math.sqrt(discrimiant)) / 2 * a;
}
else {
let answers = {};
answers["solution_one"] = (-b + Math.sqrt(discrimiant)) / (2 * a);
answers["solution_two"] = (-b - Math.sqrt(discrimiant)) / (2 * a);
return answers;
}
}
9 changes: 9 additions & 0 deletions algebra/sum_of_n_terms_of_gp/javascript/sum_of_GP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ES5 way

function sum_of_gp(n, r, a) {
return (a*(1-Math.pow(r,n)))/(1-r);
}

// ES6 way

let sum_of_gp = (n, r, a) => (a*(1-Math.pow(r,n)))/(1-r);
9 changes: 9 additions & 0 deletions geometry/arc_angle/javascript/arc_angle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ES5 way

function arc_angle(arc_len, radius) {
return (360*arc_len)/(Math.PI*2*radius);
}

// ES6 way

let arc_angle = (arc_len, radius) => (360*arc_len)/(Math.PI*2*radius);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ES5 way

function radians_to_degrees(radians){
return radians*(180/Math.PI);
}

function degrees_to_radians(degrees){
return degrees*(Math.PI/180);
}

// ES6 way

let radians_to_degrees = (radians) => radians*(180/Math.PI);

let degrees_to_radians = (degrees) => degrees*(Math.PI/180);
19 changes: 19 additions & 0 deletions geometry/triangles/javascript/Triangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ES5 way

function area(base, height) {
return (base*height)/2;
}

function heron(side1, side2, side3) {
var s = (side1+side2+side3)/2;
return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
}

// ES6 way

let area = (base, height) => (base*height)/2;

let heron = (side1, side2, side3) => {
let s = (side1+side2+side3)/2;
return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
}
51 changes: 51 additions & 0 deletions geometry/volume_formulas/javascript/volume_formulas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ES5 way

function cube_volume(edge_length) {
return edge_length**3;
}

function cuboid_volume(width, length, height) {
return width*length*height;
}

function cylinder_volume(radius, height) {
return Math.PI*height*(radius**2);
}

function sphere_volume(radius) {
return (4/3)*Math.PI*(radius**2);
}

function cone_volume(radius, height) {
return (1/3)*Math.PI*height*(radius**2);
}

function ellipsoid_volume(r1,r2,r3) {
return (4/3)*Math.PI*r1*r2*r3;
}

function pyramid_volume(width, length, height) {
return (1/3)*width*length*height;
}

function hemisphere_volume(radius) {
return (2/3)*Math.PI*(radius**2);
}

// ES6 way

let cube_volume = (edge_length) => edge_length**3;

let cuboid_volume = (width, length, height) => width*length*height;

let cylinder_volume = (radius, height) => Math.PI*height*(radius**2);

let sphere_volume = (radius) => (4/3)*Math.PI*(radius**2);

let cone_volume = (radius, height) => (1/3)*Math.PI*height*(radius**2);

let ellipsoid_volume = (r1,r2,r3) => (4/3)*Math.PI*r1*r2*r3;

let pyramid_volume = (width, length, height) => (1/3)*width*length*height;

let hemisphere_volume = (radius) => (2/3)*Math.PI*(radius**2);