123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //es6
- let afooter = document.querySelector("#afooter"),
- bfooter = document.querySelector("#bfooter"),
- calculeit = document.querySelector("#calculeit"),
- output = document.querySelector("#output");
- calculeit.addEventListener("click", function(){ calc });
- function calc() {
- output.value = ((+afooter.value) + (+bfooter.value));
- };
- afooter.oninput = calc;
- bfooter.oninput = calc;
- let table = document.createElement("table"),
- src = document.querySelector("script"),
- td = document.getElementsByTagName("td"),
- tr = document.getElementsByTagName("tr");
- document.body.insertBefore(table, src);
- let namb = "";
- for (let i = 0; i < 10; i++){
- namb += "<tr>"
- for (let j = 0; j < 10; j++){
- if (i == 0){namb += "<td>" + j + "</td>";}
- else {namb += "<td>" + i * (j === 0 ? 1 : j) + "</td>";}
- }
- namb += "</tr>"
- }
- table.innerHTML = namb
- for (let i = 0; i < 100; i++) {
- td[i].addEventListener("mouseover", function(){
- for (let x = 0; x < 10; x++){td[i].parentElement.children[x].style.backgroundColor = "#98f9d2";}
- for (let y = 0; y < 100; y++){if (td[i].cellIndex === td[y].cellIndex)
- {td[y].style.backgroundColor = "#98f9d2"
- };
- };
- });
- td[i].addEventListener("mouseout", function(){
- for (let x = 0; x < 10; x++) {td[i].parentElement.children[x].style.backgroundColor = "#b3fcde";};
- for (let y = 0; y < 100; y++) {
- if (td[i].cellIndex === td[y].cellIndex) {td[y].style.backgroundColor = "#b3fcde";};
- };
- });
- };
- //sort
- let suv = [
- {manufacturer:"Land Rover", model:"Range Rover Sport SVR", horsePower:575},
- {manufacturer:"BMW", model:"X5M", horsePower:555},
- {manufacturer:"Jeep", model:"grand cherokee trackhawk", horsePower:717},
- {manufacturer:"lamborghini", model:"Urus", horsePower:650},
- {manufacturer:"MERCEDES-BENZ", model:"GLE 63 S AMG", horsePower:558},
- {manufacturer:"Audi", model:"RS Q3", horsePower:310},
- {manufacturer:"Tesla", model:"Model X", horsePower:773},
- ]
- function sortSuv (d,b,c){
- if(b==="horsePower"){suv.sort(function(a,b){return a.horsePower - b.horsePower})
- };
- if(b==="manufacturer"){
- if(c===true){
- suv.sort(function(a,b){
- if(a.manufacturer>b.manufacturer){return 1}
- if(a.manufacturer<b.manufacturer){return -1}
- return 0
- });
- }else console.log("false")
- }
- }
- sortSuv(suv,"manufacturer", confirm("sort by company or by horsepower?"))
- sortSuv(suv,"horsePower",true);
- console.log(suv);
- // array map
- let arr = ["1", {}, null, undefined, "500", 700];
- let arrNumb = arr.map(function(set){
- return typeof(set) === 'string' ? +set : set;
- });
- console.log(arrNumb);
- // array reduce
- let arrRest = ["0", 5, 3, "string", null];
- let result = arrRest.reduce(function(previous,current){
- if(typeof(current)==='number'){
- previous*=current;
- };
- return previous;
- }, 1 )
- console.log(result);
- //object filter
- var phone = {
- brand: "meizu",
- model: "m2",
- ram: 2,
- color: "black",
- };
- let phoneResult={};
- function filter(val,key,obj) {
- for(let [keY, vaL] of Object.entries(obj)){
- if (keY == key || vaL == val) {
- phoneResult[keY] = vaL;
- }
- }
- console.log(phoneResult);
- return phoneResult;
- }
- filter(2, 'color', phone);
- //object map
- let objectTest = {name: "Иван", age: 17}, result={};
- function maps(){
- for(let [val,key] of Object.entries(objectTest)){
- result[val+"_"]=key+"$";
- };
- return result;
- };
- console.log(maps());
- //sum
- function sum (s){
- if (s===1)return 1;
- return s + sum(s-1);
- }
- console.log(sum(28))
|