Skip to content

Instantly share code, notes, and snippets.

View junojo's full-sized avatar
🌴
On vacation

Juno Jo junojo

🌴
On vacation
View GitHub Profile
@junojo
junojo / Binary Addition
Last active September 4, 2021 08:23
Implement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition. The binary number returned should be a string.
const addBinary = (a, b) => (a + b).toString(2);
console.log(addBinary(1, 5))
const convertToBinary = (number) => {
return number.toString(2);
}
@junojo
junojo / Century Converter
Last active September 4, 2021 08:23
The first century spans from the year 1 up to and including the year 100, The second - from the year 101 up to and including the year 200, etc.
function century(year) {
let centuryCount = 0;
while (year > 0){
console.log(year);
year = year - 100;
centuryCount = centuryCount + 1;
}
return centuryCount;
}
@junojo
junojo / Is this a triangle?
Created September 4, 2021 08:22
Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted).
function isTriangle(a,b,c)
{
var arr = [a,b,c].sort(function(a, b) {
return a - b;
});
return arr[0] + arr[1] > arr[2] ? true : false;
}
@junojo
junojo / Format a string of names like 'Bart, Lisa & Maggie'.
Created September 4, 2021 08:29
Given: an array containing hashes of names Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand.
function list(names){
let str = '';
if (names.length !== 0) {
let last = names.pop();
str = names.map( (val, i, arr) => {
if (i !== arr[arr.length - 1]) {
return val.name;
}
}).join(', ')
@junojo
junojo / Build Tower
Created September 4, 2021 08:31
Build Tower Build Tower by the following given argument: number of floors (integer and always greater than 0). Tower block is represented as * Python: return a list; JavaScript: returns an Array; C#: returns a string[]; PHP: returns an array; C++: returns a vector<string>; Haskell: returns a [String]; Ruby: returns an Array; Lua: returns a Table…
function towerBuilder(nFloors) {
let solution = [];
for(let i=0; i < nFloors; i++){
solution.push(" ".repeat((nFloors - i) - 1) + "*".repeat((i*2) + 1) + " ".repeat((nFloors - i) - 1));
}
return solution;
}
@junojo
junojo / problem.md
Last active September 4, 2021 08:38
Find the missing letter

Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.

You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. The array will always contain letters in only one case.

Example:

['a','b','c','d','f'] -> 'e'
['O','Q','R','S'] -> 'P'
@junojo
junojo / problem.md
Created September 4, 2021 08:38 — forked from tomanistor/problem.md
Find the missing letter

Find the missing letter

Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.

You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. The array will always contain letters in only one case.

Example:

@junojo
junojo / problem.md
Last active September 11, 2021 08:12
Keep Hydrated!

Nathan loves cycling.

Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling.

You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value.

For example:

time = 3 ----> litres = 1

@junojo
junojo / problem.md
Created September 11, 2021 08:30
Number of People in the Bus

Number of people in the bus There is a bus moving in the city, and it takes and drop some people in each bus stop.

You are provided with a list (or array) of integer arrays (or tuples). Each integer array has two items which represent number of people get into bus (The first item) and number of people get off the bus (The second item) in a bus stop.

Your task is to return number of people who are still in the bus after the last bus station (after the last array). Even though it is the last bus stop, the bus is not empty and some people are still in the bus, and they are probably sleeping there :D

Take a look on the test cases.

Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the return integer can't be negative.

@junojo
junojo / problem.md
Created September 11, 2021 08:36
Highest Scoring Word

Given a string of words, you need to find the highest scoring word.

Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc.

You need to return the highest scoring word as a string.

If two words score the same, return the word that appears earliest in the original string.

All letters will be lowercase and all inputs will be valid.