This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function() { | |
| $('.page-scroll').click(function(event) { | |
| event.preventDefault(); | |
| $('html, body').animate( | |
| {scrollTop: $( $(this).attr('href') ).offset().top } | |
| , 1500 ); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Obj (){ | |
| const _ins = this; | |
| const _proto = Obj.prototype; | |
| Obj = function(){ | |
| return _ins; | |
| } | |
| Obj.prototype = _proto | |
| Obj.prototype.constructor = Obj; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fact(n){ | |
| var res = n; | |
| if(n < 0) return "Undefined"; | |
| for(let i = n-1; i > 1; i--){ | |
| res *= i; | |
| } | |
| return res; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // число является простым если делится без остатка только на себя и 1 | |
| // т.е ни на одно перед собой | |
| function isPrime(n){ | |
| for(let i = 2; i < n; i++){ | |
| if(n % i === 0){ | |
| return false; | |
| } | |
| } | |
| return n > 1; |
OlderNewer