Skip to content

Instantly share code, notes, and snippets.

Avatar
🌈
Got stuck in infinite loop

Artur ar2zee

🌈
Got stuck in infinite loop
View GitHub Profile
@ar2zee
ar2zee / sortArrayOfObject.js
Created June 12, 2019 13:50
Sorting an array of Object
View sortArrayOfObject.js
const purchases = [
{ name: 'Popcorn', price: 5.75 },
{ name: 'Movie Ticket', price: 12 },
{ name: 'Soda', price: 3.75 },
{ name: 'Candy', price: 5 },
];
const sortByMapped = (map,compareFn) => (a,b) => compareFn(map(a),map(b));
const byValue = (a,b) => a - b;
const toPrice = e => e.price;
@ar2zee
ar2zee / Max_element_of_arrayS.js
Created December 25, 2017 21:44
Max element of each array using spread operator
View Max_element_of_arrayS.js
var arr = [[4, 2, 7, 1], [20, 70, 40, 90], [1, 2, 0], [1, 2, 0] , [1, 2, 0] , [1, 2, 0]]; // ➞ [7, 90, 2]
function findLargestNums(arr) {
return arr.map(x => Math.max(...x));
}
console.log(findLargestNums(arr))
@ar2zee
ar2zee / classExample.js
Created June 6, 2017 00:26
example of work with 'class' keyword in JS
View classExample.js
class Mammal {
constructor(sound) {
this._sound = sound;
}
talk() {
return this._sound;
}
}
class Dog extends Mammal {
@ar2zee
ar2zee / reduceFunction.js
Created May 31, 2017 02:18
Example of reduce function with array function
View reduceFunction.js
var orders = [
{amount: 250},
{amount: 300},
{amount: 350},
{amount: 400}
];
// var quintyty = orders.reduce (function(sum, order) { /*sum- first arguments our callback, order- iterated item */
// console.log('hello', sum , order);
@ar2zee
ar2zee / filterFunction.js
Created May 30, 2017 17:03
example filter function wih array
View filterFunction.js
var animals = [
{name : 'artur', food: 'potatoes'},
{name : 'sergey', food: 'fries'},
{name : 'anton', food: 'fries'},
{name : 'petya', food: 'cream'},
{name : 'oksana', food: 'chips'},
{name : 'lesya', food: 'meat'},
{name : 'julya', food: 'vegies'},
{name : 'sasha', food: 'sour_cream'}
];
@ar2zee
ar2zee / mapFunction.js
Created May 30, 2017 16:18
example of map function with array
View mapFunction.js
var animals = [
{name : 'artur', food: 'fries'},
{name : 'sergey', food: 'fries'},
{name : 'anton', food: 'fries'},
{name : 'petya', food: 'fries'},
{name : 'oksana', food: 'fries'},
{name : 'lesya', food: ''},
{name : 'julya'},
{name : 'sasha', food: 'fries'}
];
@ar2zee
ar2zee / JqueryPreloader.js
Created April 25, 2017 17:51
Jquery preloader
View JqueryPreloader.js
#loader {
background: none repeat scroll 0 0 #ffffff;
bottom: 0;
height: 100%;
left: 0;
position: fixed;
right: 0;
top: 0;
width: 100%;
z-index: 9999;
@ar2zee
ar2zee / forInpractise.js
Created April 12, 2017 21:25
for in example
View forInpractise.js
var array = ['arg' , 'sannya' , 'katya' , 'ukr' ,'etc'];
for ( word in array) {
console.log(array[word]);
}
@ar2zee
ar2zee / name.js
Created April 10, 2017 20:56
easy method with strings
View name.js
var Genius = 'AlBErt EinsTeIn'
function changingName(oldName){
var FixedName = oldName;
var names = oldName.split(' ');
names[1] = names[1].toUpperCase();
names[0] = names[0].slice(0,1).toUpperCase() + names[0].slice(1).toLowerCase();
FixedName = names.join(' ');
return FixedName;
@ar2zee
ar2zee / forEach.js
Last active April 2, 2017 23:42
forEach method array
View forEach.js
var donuts = ['sanya', 'andrey', 'petya', 'ksusha'];
donuts.forEach(function(donut){
donut += ' HOLE';
donut = donut.toUpperCase();
console.log(donut);
});