Skip to content

Instantly share code, notes, and snippets.

@AndriiBozh
AndriiBozh / filter list.txt
Created January 4, 2019 18:30
CodeWars: List Filtering
ASSIGNMENT
_____________________________
In this kata you will create a function that takes a list of non-negative integers and strings
and returns a new list with the strings filtered out.
Example:
filter_list([1,2,'a','b']) == [1,2]
filter_list([1,'a','b',0,15]) == [1,0,15]
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
@AndriiBozh
AndriiBozh / capitalize a string.txt
Created December 27, 2018 23:42
CodeWars: Capitalization
ASSIGNMENT
_________________________________________
write a helper function to capitalize a string (that contains a single word).
Don't worry about numbers, special characters, or non-string types being passed to the function.
The string lengths will be from 1 character up to 10 characters, but will never be empty.
_________________________________________
SOLUTION
_________________________________________
@AndriiBozh
AndriiBozh / total amount of points.txt
Created December 27, 2018 22:53
CodeWars: Total Amount of Points
ASSIGNMENT
_________________________________________
Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the array.
For example: ["3:1", "2:2", "0:1", ...]
Write a function that takes such list and counts the points of our team in the championship. Rules for counting points for each match:
if x>y - 3 points
if x<y - 0 point
@AndriiBozh
AndriiBozh / cash_register.txt
Created November 19, 2018 09:51
Cash Register
ASSIGNMENT
_______________________________________________________________________________________________________________________________
Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price),
payment as the second argument (cash), and cash-in-drawer (cid) as the third argument.
cid is a 2D array listing available currency.
The checkCashRegister() function should always return an object with a status key and a change key.
@AndriiBozh
AndriiBozh / Calculate Orbital Period.txt
Created November 4, 2018 06:02
Calculate Orbital Period
ASSIGNMENT
________________________________________________________________________________
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
The array will contain objects in the format {name: 'name', avgAlt: avgAlt}.
You can read about orbital periods on Wikipedia.
The values should be rounded to the nearest whole number. The body being orbited is Earth.
@AndriiBozh
AndriiBozh / Telephone Number Validator.txt
Created November 2, 2018 11:57
Telephone Number Validator (Reg Ex)
ASSIGNMENT
__________________________________________________________________________________________________________________________
Return true if the passed string looks like a valid US phone number.
The user may fill out the form field any way they choose as long as it has
the format of a valid US number. The following are examples of valid formats for US numbers
(refer to the tests below for other variants):
555-555-5555
(555)555-5555
@AndriiBozh
AndriiBozh / FIlter and Map Methods to extract data from an Array.txt
Last active October 10, 2018 11:02
Use the filter Method to Extract Data from an Array
ASSIGNMENT:
The variable watchList holds an array of objects with information on several movies.
Use a combination of filter and map to return a new array of objects with only title and rating keys,
but where imdbRating is greater than or equal to 8.0.
Note that the rating values are saved as strings in the object
and you may want to convert them into numbers to perform mathematical operations on them.
__________________________________________
//NOTE In fact, I didn't have to convert strings into numbers, I used '>=' (greater than or equal) symbol and
@AndriiBozh
AndriiBozh / Higher Order Arrow Functions.txt
Created September 20, 2018 19:45
ES6: Write Higher Order Arrow Functions
ASSIGNMENT:
Use arrow function syntax to compute the square of only the positive integers (fractions are not integers)
in the array realNumberArray and store the new array in the variable squaredIntegers.
_____________________________________________________________________________________________
SOLUTION:
_____________________________________________________________________________________________
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
ASSIGNMENT
_____________________________________
Find the missing letter in the passed letter range and return it.
If all letters are present in the range, return undefined.
_____________________________________
SOLUTION
_____________________________________
ASSIGNMRENT
_______________________________________________
The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
Return the provided character as the first element in each array.
For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]]
The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
_______________________________________________