Skip to content

Instantly share code, notes, and snippets.

View andreiskandar's full-sized avatar
🎯
Focusing

Andre Iskandar andreiskandar

🎯
Focusing
View GitHub Profile
@andreiskandar
andreiskandar / gist:86e9974203f76930173b044a6133c730
Created June 30, 2020 19:15
Sum two largest numbers in the array
/*
In this exercise, we will be given an array of 2 or more numbers.
We will then have to find the two largest numbers in that array, and sum them together.
Input
const sumLargestNumbers = function(data) {
// Put your solution here
};
console.log(sumLargestNumbers([1, 10]));
@andreiskandar
andreiskandar / gist:3b0e6789c8f83b948bf9888ec2953e99
Created June 30, 2020 19:19
Adding only the numbers in the array that match given condition
/*
For this kata, we'll be adding only the numbers in the array which match the given condition.
Input
const conditionalSum = function(values, condition) {
// Your code here
};
console.log(conditionalSum([1, 2, 3, 4, 5], "even"));
console.log(conditionalSum([1, 2, 3, 4, 5], "odd"));
@andreiskandar
andreiskandar / gist:c4c2085eb115dc9fe763cfaa4055e07e
Created June 30, 2020 19:21
Countiny number of vowels that appear in a given string
/*
In this exercise, we will be counting the number of vowels that appear in a given string. For this exercise, consider the following to be vowels: a, e, i, o, and u.
INPUT
const numberOfVowels = function(data) {
// Put your solution here
};
console.log(numberOfVowels("orange")); //3
console.log(numberOfVowels("lighthouse labs")); //5
@andreiskandar
andreiskandar / gist:19bf4a9b00c247c29f63d73e8f81f7ff
Created June 30, 2020 19:23
Determine instructors who have longest name in the object
/*
In this exercise, we will be given a list of instructors and have to determine which instructor has the longest name.
Input
const instructorWithLongestName = function(instructors) {
// Put your solution here
};
console.log(instructorWithLongestName([
{name: "Samuel", course: "iOS"},
@andreiskandar
andreiskandar / gist:9965281e1df7c0f2424964049da9ecb3
Created June 30, 2020 19:24
Replacing all whitespaces with '%20' from given string
/*
Kata 5 - Percent Encoded String
In this exercise, we will be given a normal string of words and turn it into a percent-encoded string by replacing all whitespace with %20.
Percent Encoding
Take a look at the following URL, specifically the last part:
This URL will perform a google search for the term "lighthouse labs". Notice that when the string "lighthouse labs" is part of a URL, the space is replaced with %20.
@andreiskandar
andreiskandar / gist:431ae9ccb2e35f3417b4a6adbb488330
Created June 30, 2020 19:29
Finding array coordinates of a string using nested for loops
/*
We need to write a function called whereCanIPark() that returns the coordinates of an available parking spot for the vehicle,
or returns false if there is no available spot. Our function receives an array of arrays representing parking spots,
and a string with type of the vehicle that is looking for a parking spot.
*/
const whereCanIPark = function (spots, vehicle) {
for(let y = 0; y < spots.length; y++){
for(let x = 0; x < spots[y].length; x++){
if(vehicle === 'regular'){
/*
For this challenge we will implement a function called checkAir(), which will check a collection of air samples.
The function will take in two arguments. The first argument is an array of strings, where each string represents
a small air sample that is either clean or dirty. The second argument is a number representing the highest
acceptable amount of dirty samples. For example, a threshold of 0.4 means that there must be less than 40% of
total samples classified as dirty for our air to be considered clean. Our function must return Polluted if there
are too many dirty air samples, or Clean if the proportion of dirty samples is below the threshold.
*/
const checkAir = function (samples, threshold) {
/*
Create a function named repeatNumbers that will return a string with each of the given
values repeated the appropriate number of times, if there are multiple sets of values
each set should be separated by a comma. If there is only one set of values then you
should omit the comma.
*/
const repeatNumbers = function(data) {
let str = '';
/*
Create a function named multiplicationTable that receives a number maxValue as input
and creates a square multiplication table where maxValue is the largest value in the table.
*/
const multiplicationTable = function(maxValue) {
let i = '';
for(let y = 1; y <= maxValue; y++){
for(let x = 1; x <= maxValue; x++){
const PI = 3.14159 ;
const sphereVolume = function (radius) {
return 4 / 3 * PI * Math.pow(radius, 3);
}
// console.log(4186 < sphereVolume(10) && sphereVolume(10) < 4189);
const coneVolume = function (radius, height) {
return PI * Math.pow(radius, 2) * height / 3;