Skip to content

Instantly share code, notes, and snippets.

View ZackFox's full-sized avatar
😎
looking for a job

Сергей ZackFox

😎
looking for a job
View GitHub Profile
$(function() {
$('.page-scroll').click(function(event) {
event.preventDefault();
$('html, body').animate(
{scrollTop: $( $(this).attr('href') ).offset().top }
, 1500 );
});
});
function makeTree(list, node) {
const tree = [];
list.forEach((item) => {
if (item.parent_id !== null) {
if(list[item.parent_id-1]["children"] === undefined){
list[item.parent_id-1].children = [];
}
list[item.parent_id-1].children.push(item);
} else {
function makeTree(list, node) {
const map = {};
const tree = [];
for(let i = 0; i < list.length; i++){
map[list[i].id] = list[i];
map[list[i].id].children = [];
}
for(let i = 1; i < list.length; i++){
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
background-color: #f1f1f1;
font-family: Arial, Helvetica, sans-serif;
}
@ZackFox
ZackFox / bubble.js
Last active March 28, 2019 07:11
bubble sort
for(let i = 0; i < arr.length; i++){
for(let j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
const temp = arr[i];
arr[i] = arr[j]
arr[j] = temp;
}
}
}
function Obj (){
const _ins = this;
const _proto = Obj.prototype;
Obj = function(){
return _ins;
}
Obj.prototype = _proto
Obj.prototype.constructor = Obj;
}
function CarFactory (){}
CarFactory.prototype.drive = function(){
console.log(`i have ${this.doors} doors`);
}
CarFactory.make = function(type){
if(typeof CarFactory[type] !== "function" ){
throw Error("Car not found");
}
function GCD(a,b){
let res;
for(let i = 0; i< Math.max(a,b); i++){
if(a % i === 0 && b % i === 0){
res = i;
}
}
return res
}
function fact(n){
var res = n;
if(n < 0) return "Undefined";
for(let i = n-1; i > 1; i--){
res *= i;
}
return res;
}
// число является простым если делится без остатка только на себя и 1
// т.е ни на одно перед собой
function isPrime(n){
for(let i = 2; i < n; i++){
if(n % i === 0){
return false;
}
}
return n > 1;