Skip to content

Instantly share code, notes, and snippets.

View juliaamosova's full-sized avatar
🏠
Working from home

Julia Amosova juliaamosova

🏠
Working from home
View GitHub Profile
@juliaamosova
juliaamosova / second-index.js
Last active May 3, 2018 01:29
Checkio: Return the second index of a symbol in a given text.
/*
You are given two strings and you have to find an index of the second occurrence of the second string in the first one.
Let's go through the first example where you need to find the second occurrence of "s" in a word "sims". It’s easy to find its first occurrence with a function indexOf which will point out that "s" is the first symbol in a word "sims" and therefore the index of the first occurrence is 0. But we have to find the second "s" which is 4th in a row and that means that the index of the second occurrence (and the answer to a question) is 3.
Input: Two strings.
Output: Int or undefined
*/
@juliaamosova
juliaamosova / first-word.js
Last active May 3, 2018 01:30
Checkio: Find the first word in a given string.
/*
You are given a string where you have to find its first word.
When solving a task pay attention to the following points:
There can be dots and commas in a string.
A string can start with a letter or, for example, a dot or space.
A word can contain an apostrophe and it's a part of a word.
The whole text can be represented with one word and that's it.
Input: A string.
@juliaamosova
juliaamosova / plugin.php
Last active April 1, 2018 01:30 — forked from joncave/plugin.php
An intentionally vulnerable plugin developed for WordPress plugin author education.http://make.wordpress.org/plugins/2013/04/09/intentionally-vulnerable-plugin/
<?php
/* Plugin Name: Damn Vulnerable WordPress Plugin
* Description: Intentionally vulnerable plugin for plugin author education
* Version: 0.1
* Plugin URI: http://make.wordpress.org/plugins/2013/04/09/intentionally-vulnerable-plugin/
* Author: Jon Cave
* Author URI: http://joncave.co.uk
* License: GPLv2+
*
* DO NOT RUN THIS PLUGIN ON AN INTERNET ACCESSIBLE SITE
@juliaamosova
juliaamosova / you-are-old.js
Created September 29, 2017 03:33
Class vs. Instance Challenge
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
@juliaamosova
juliaamosova / array-elements-sum.js
Created September 28, 2017 03:34
Given an array of integers N, find the sum of its elements.
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
@juliaamosova
juliaamosova / conditional-statement.js
Created September 28, 2017 02:51
Given an integer n, perform several conditional actions.
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
@juliaamosova
juliaamosova / left-rotation.js
Created September 27, 2017 01:49
Given an array of n integers and a number , d, perform d left rotations on the array. Then print the updated array as a single line of space-separated integers.
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
@juliaamosova
juliaamosova / total-meal-cost.js
Created September 26, 2017 23:47
Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost.
var tip = mealCost * tipPercent/100;
var tax = mealCost * taxPercent/100;
var totalCost = Math.round(mealCost + tip + tax);
console.log("The total meal cost is " + totalCost + " dollars.");
@juliaamosova
juliaamosova / stdin-stream.js
Created September 26, 2017 02:39
Hackerrank: Using readLine() to read a stream from STDIN
// Declare second integer, double, and String variables.
var i2;
var d2;
var s2;
// Read and save an integer, double, and String to your variables.
/* The parseInt() function parses a string argument and returns an integer of the specified radix
(the base in mathematical numeral systems).*/
i2 = parseInt(readLine());
@juliaamosova
juliaamosova / hourglass-sum.js
Created September 25, 2017 03:38
Calculate the hourglass sum for every hourglass in array
// i - row
// j - column
function main() {
var arr = [];
var sum = 0;
var maxSum = -63;
for(arr_i = 0; arr_i < 6; arr_i++){
arr[arr_i] = readLine().split(' ');
arr[arr_i] = arr[arr_i].map(Number);