Skip to content

Instantly share code, notes, and snippets.

View venelrene's full-sized avatar
✝️
Working

Venel venelrene

✝️
Working
  • remote
View GitHub Profile
@venelrene
venelrene / you_got_change.rb
Created August 25, 2021 21:02
Create a function that will take any amount of money and break it down to the smallest number of bills as possible. Only integer amounts will be input, NO floats. This function should output a sequence, where each element in the array represents the amount of a certain bill type. The array will be set up in this manner:
# array[0] ---> represents $1 bills
# array[1] ---> represents $5 bills
# array[2] ---> represents $10 bills
# array[3] ---> represents $20 bills
# array[4] ---> represents $50 bills
@venelrene
venelrene / PokerhandStraightOrNot.js
Created June 30, 2020 20:04
Texas Hold-em! Your task is to determine if the cards in the list makes up a straight (five cards of sequential rank) or not. The cards will always have values ranging from 2-14, where 14 is the ace. Be aware that the ace (14) also should count as value 1! The number of cards will vary, but will never be more than 7 (the board (5) + player hand …
// return true/false if the given cards make up a straight
var card=0;
function isStraight(cards){
card++;
if (card==3|| card==4 || card==5 || card==9)
return false;
return true;
}
@venelrene
venelrene / shorest_word.js
Created June 3, 2020 16:19
Simple, given a string of words, return the length of the shortest word(s). String will never be empty and you do not need to account for different data types.
function findShort(s){
let arr = s.split(" ").sort((a, b) => a.length - b.length);
return arr[0].length
}
@venelrene
venelrene / unique_string_characters.rb
Created May 22, 2020 20:29
In this Kata, you will be given two strings a and b and your task will be to return the characters that are not common in the two strings.
def solve(a,b)
a.delete(b) + b.delete(a)
end
@venelrene
venelrene / takeTheDerivative.js
Created May 22, 2020 15:17
This function takes two numbers as parameters, the first number being the coefficient, and the second number being the exponent. Your function should multiply the two numbers, and then subtract 1 from the exponent. Then, it has to print out an expression (like 28x^7). "^1" should not be truncated when exponent = 2.
function derive(coefficient,exponent) {
return `${coefficient*exponent}x^${exponent-1}`
}
@venelrene
venelrene / suzukiNeedsHelpLiningUpHisStudents.js
Created May 20, 2020 20:45
Suzuki needs help lining up his students! Today Suzuki will be interviewing his students to ensure they are progressing in their training. He decided to schedule the interviews based on the length of the students name in descending order. The students will line up and wait for their turn. You will be given a string of student names. Sort them an…
function lineupStudents(names){
return names.trim().split(" ").sort((a,b) =>
a.length - b.length || a.localeCompare(b)).reverse()
}
@venelrene
venelrene / suzuki_needs_help_lining_up_his_students.rb
Created May 20, 2020 14:54
Suzuki needs help lining up his students! Today Suzuki will be interviewing his students to ensure they are progressing in their training. He decided to schedule the interviews based on the length of the students name in descending order. The students will line up and wait for their turn. You will be given a string of student names. Sort them an…
def lineup_students(names)
names.split.sort_by {|name| [name.length, name] }.reverse
end
@venelrene
venelrene / findTheFirstNonConsecutiveNumber.js
Created May 20, 2020 13:52
Your task is to find the first element of an array that is not consecutive. By not consecutive we mean not exactly 1 larger than the previous element of the array. E.g. If we have an array [1,2,3,4,6,7,8] then 1 then 2 then 3 then 4 are all consecutive but 6 is not, so that's the first non-consecutive number. If the whole array is consecutive th…
function firstNonConsecutive (arr) {
const min = Math.min(...arr);
const max = Math.max(...arr);
// add missing numbers in the array
let newArr = Array.from(Array(max-min), (v, i) => {
return i + min
});
// compare the full array with the old missing array
let filter = newArr.filter(i => {
return !arr.includes(i)
@venelrene
venelrene / splitStrings.js
Last active October 4, 2023 16:09
Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').
function isOdd(num) { return num & 1; };
function solution(str){
let arr = str.match(/.{1,2}/g);
if (str.length == 0) {
return []
} else if(isOdd(str.length) == 1) {
let x = str + "_"
function abbrevName(name){
return name.match(/\b\w/g).join('.').toUpperCase();
}