Skip to content

Instantly share code, notes, and snippets.

Avatar

Ivo Culic ifkas

View GitHub Profile
@ifkas
ifkas / reduce_exercise_one_number_solution.js
Created Oct 13, 2020
Reduce exercise number solution
View reduce_exercise_one_number_solution.js
let total = numbers.reduce((accumulator, number) => {
return accumulator += number;
}, 0);
@ifkas
ifkas / reduce_exercise_one_numbers.js
Created Oct 13, 2020
Reduce exercise one numbers
View reduce_exercise_one_numbers.js
const numbers = [1,3,5,10,20];
@ifkas
ifkas / reduce_exercise_two.js
Created Oct 13, 2020
Reduce - exercise two solution
View reduce_exercise_two.js
function longest(s1, s2) {
const allLetters = s1 + s2;
const distinctLetters = allLetters.split('').reduce((distinctLetters, currentLetter) => {
distinctLetters[currentLetter] = true;
return distinctLetters;
}, {});
const letters = Object.keys(distinctLetters);
return letters.sort().join('');
}
@ifkas
ifkas / final_result.js
Created Oct 13, 2020
Final result - exercise 2
View final_result.js
a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz"
View reduce_exercise_one.js
let apples = shelf.reduce((accumulator, number) => {
if(number.includes("apple")) {
return accumulator += 1;
} else {
return accumulator;}
}, 0);
@ifkas
ifkas / array_for_reduce.js
Last active Oct 13, 2020
Array1 - Reduce
View array_for_reduce.js
const shelf = [
"blueberry pie",
"apple tart",
"meat pie",
"apple pie",
"banana bread",
"pumpkin pie",
"apple crumble",
"donuts"
];
@ifkas
ifkas / bg_images.json
Last active Jun 5, 2019
Json with couple of unsplash images
View bg_images.json
[{
"bg_image":
"https://images.unsplash.com/photo-1546924635-8a0e468028b0?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80"
},
{
"bg_image":
"https://images.unsplash.com/photo-1546165388-7b9d5231867e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1502&q=80"
},
{
"bg_image":
View hyoetyoe.json
{
"fruits": [
{
"orange": "<svg class='sv' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Capa_1' x='0px' y='0px' viewBox='0 0 512 512' style='enable-background:new 0 0 512 512;' xml:space='preserve'><path style='fill:#FFA800;' d='M256,91.687c-115.879,0-210.156,94.274-210.156,210.156C45.843,417.723,140.121,512,256,512 s210.157-94.277,210.157-210.156C466.156,185.961,371.879,91.687,256,91.687z'/> <path style='fill:#FE9700;' d='M256,91.687c-11.928,0-23.609,1.051-35,2.969c99.271,16.719,175.156,103.235,175.156,207.188 S320.272,492.309,221,509.031c11.391,1.918,23.072,2.969,35,2.969c115.879,0,210.157-94.277,210.157-210.156 C466.156,185.961,371.879,91.687,256,91.687z'/> <path style='fill:#006837;' d='M256,159.419c-6.617,0.001-12.805-4.135-15.106-10.734C207.543,53.082,255.012,6.362,257.051,4.419 c6.402-6.1,16.527-5.852,22.621,0.539c6.059,6.355,5.855,16.396-0.422,22.506c-1.703,1.724-34.203,35.971-8.144,110.682 c2.914,8.343-1.492,17.467-9.836,20.377C259.527,159.131,
View patterns.json
{
"Melt": "%3Csvg width='24' height='20' viewBox='0 0 24 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 18c0-1.105.887-2 1.998-2 1.104 0 2-.895 2.002-1.994V14v6h-4v-2zM0 13.998C0 12.895.888 12 2 12c1.105 0 2 .888 2 2 0 1.105.888 2 2 2 1.105 0 2 .888 2 2v2H0v-6.002zm16 4.004A1.994 1.994 0 0 1 14 20c-1.105 0-2-.887-2-1.998v-4.004A1.994 1.994 0 0 0 10 12c-1.105 0-2-.888-2-2 0-1.105-.888-2-2-2-1.105 0-2-.887-2-1.998V1.998A1.994 1.994 0 0 0 2 0a2 2 0 0 0-2 2V0h8v2c0 1.105.888 2 2 2 1.105 0 2 .888 2 2 0 1.105.888 2 2 2 1.105 0 2-.888 2-2 0-1.105.888-2 2-2 1.105 0 2-.888 2-2V0h4v6.002A1.994 1.994 0 0 1 22 8c-1.105 0-2 .888-2 2 0 1.105-.888 2-2 2-1.105 0-2 .887-2 1.998v4.004z' fill='%232f2e31' fill-opacity='0.57' fill-rule='evenodd'/%3E%3C/svg%3E",
"Overlapping Diamonds": "%3Csvg width='48' height='64' viewBox='0 0 48 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M48 28v-4L36 12 24 24 12 12 0 24v4l4 4-4 4v4l12 12 12-12 12 12 12-12v-4l-4-4 4-4zM8 32l-6-6 10-10 10 10-6 6 6 6-10 10L2 38l6-6zm12 0l4-4
@ifkas
ifkas / jsClosure5.js
Last active Feb 23, 2018
Closure binding example
View jsClosure5.js
let count = 0;
function appleColor(color) {
return function(type) {
count++;
if(count === 1) {
document.getElementById('ate').innerHTML += '<div class="message">' + 'I ate ' + count + ' apple. ' + '<br/>' + 'It was ' + type + ' type with shiny bright ' + color + ' color. ' + `<svg id="appleSvg" fill="${color}" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 50 50.001" style="enable-background:new 0 0 50 50.001;" xml:space="preserve"> <path d="M26.12,14.488c0.879-1.468,2.27-3.569,4.027-5.585h0.002c1.488-1.711,4.402-3.907,4.402-3.907 c0.438-0.331,0.391-0.792-0.107-1.024l-3.522-1.646c-0.498-0.233-1.175-0.063-1.505,0.376c0,0-2.605,3.737-5.671,11.692 c-9.48-4.288-18.491,1.718-18.491,12.162c0,10.909,8.393,27.48,19.743,22.478c11.954,5.173,19.749-11.568,19.749-22.478 C44.747,16.022,36.647,9.846,26.12,14.488z"/> <path d="M23.997,10.955c0.548-0.046,1.032-0.531,1.076-1.078c0,0,0.352-4.266-2.621-7.242c-2.982-2.977-7.2
You can’t perform that action at this time.