Skip to content

Added my library. #29

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
50 changes: 50 additions & 0 deletions hackerrank/10 Days of JavaScript/0 - Data Types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

/* All three parameters to this function are strings. */
function performOperation(secondInteger, secondDecimal, secondString) {
const firstInteger = 4;
const firstDecimal = 4.0;
const firstString = 'HackerRank ';

console.log(firstInteger + parseInt(secondInteger));
console.log(firstDecimal + parseFloat(secondDecimal));
console.log(firstString + secondString);
}

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
function main() {
const secondInteger = readLine();
const secondDecimal = readLine();
const secondString = readLine();

performOperation(secondInteger, secondDecimal, secondString);
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
42 changes: 42 additions & 0 deletions hackerrank/10 Days of JavaScript/0 - Hello World.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

function greeting(message) {
console.log('Hello, World!');
console.log(message);
}

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
function main() {
const parameterVariable = readLine();

greeting(parameterVariable);
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
47 changes: 47 additions & 0 deletions hackerrank/10 Days of JavaScript/1 - Arthmetic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

function getArea(length, width) {
return length * width;
}

function getPerimeter(length, width) {
return 2 * (length + width);
}

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
function main() {
const length = +(readLine());
const width = +(readLine());

console.log(getArea(length, width));
console.log(getPerimeter(length, width));
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
47 changes: 47 additions & 0 deletions hackerrank/10 Days of JavaScript/1 - Fnxn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

function factorial(n) {
if (n < 0) {
throw "Input to 'factorial()' must be non-negative";
} else if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
function main() {
const n = +(readLine());

console.log(factorial(n));
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
48 changes: 48 additions & 0 deletions hackerrank/10 Days of JavaScript/1 - Let.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

function main() {
const PI = Math.PI;
const r = parseFloat(readLine());

console.log(PI * (r ** 2));
console.log(2 * PI * r);

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
try {
// Attempt to redefine the value of constant variable PI
PI = 0;
// Attempt to print the value of PI
console.log(PI);
} catch(error) {
console.error("You correctly declared 'PI' as a constant.");
}
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
61 changes: 61 additions & 0 deletions hackerrank/10 Days of JavaScript/2 - If.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

function getGrade(score) {
let grade;

if (score > 30) {
throw "score must be <= 30";
} else if (score > 25) {
grade = 'A';
} else if (score > 20) {
grade = 'B';
} else if (score > 15) {
grade = 'C';
} else if (score > 10) {
grade = 'D';
} else if (score > 5) {
grade = 'E';
} else if (score >= 0) {
grade = 'F';
} else {
throw "score must be non-negative";
}

return grade;
}

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
function main() {
const score = +(readLine());

console.log(getGrade(score));
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
58 changes: 58 additions & 0 deletions hackerrank/10 Days of JavaScript/2 - Loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});

main();
});

function readLine() {
return inputString[currentLine++];
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */

function isVowel(ch) {
ch = ch.toLowerCase();
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

function vowelsAndConsonants(s) {
let vowels = [];
let consonants = [];

for (let ch of s) {
if (isVowel(ch)) {
vowels.push(ch);
} else {
consonants.push(ch);
}
}

console.log(vowels.join('\n'));
console.log(consonants.join('\n'));
}

/* ************************************************************************** */
/* --------------------------- begin locked code ---------------------------- */
function main() {
const s = readLine();

vowelsAndConsonants(s);
}
/* ---------------------------- end locked code ----------------------------- */
/* ************************************************************************** */
Loading