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
| const classObj = document.querySelectorAll('.mv-title'); | |
| const classArr = classObj.map((value,index) => [value.offsetWidth]); | |
| const sumOfWidths = classArr.reduce((total, value) => total + value); | |
| console.log(sumOfWidths); |
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
| Value | Longhand | Summary | |
|---|---|---|---|
| initial | 0 1 auto | cannot grow but can shrink when there isn't enough space | |
| auto | 1 1 auto | can grow and shrink to fit available space | |
| none | 0 0 auto | cannot grow or shrink AKA inflexible | |
| <positive-number> | <positive-number> 1 0 | can grow and shrink with extent of growth depending on flex factor |
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
| //Deep copying objects | |
| //Method 1 | |
| var cloneObject = jsonObject => JSON.parse(JSON.stringify(jsonObject)); | |
| //Method 2 | |
| function cloneObject(jsonObject){ | |
| var cloned_obj = {}; | |
| for(let key in jsonObject){ | |
| if(jsonObject.hasOwnProperty(key)){ | |
| cloned_obj[key] = jsonObject[key]; |
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
| https://reqres.in/ | |
| http://www.omdbapi.com/ |
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 textSize(text) { | |
| if (!d3) return; | |
| var container = d3.select('body').append('svg'); | |
| container.append('text').attr('x', -99999).attr('y',-99999).text(text); | |
| var size = container.node().getBBox(); | |
| container.remove(); | |
| return { width: size.width, height: size.height }; | |
| } | |
| // Usage: textSize("This is a very long text"); |
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 array_intersect(){var a,b,c,d,e,f,g=[],h={},i;i=arguments.length-1;d=arguments[0].length;c=0;for(a=0;a<=i;a++){e=arguments[a].length;if(e<d){c=a;d=e}}for(a=0;a<=i;a++){e=a===c?0:a||c;f=arguments[e].length;for(var j=0;j<f;j++){var k=arguments[e][j];if(h[k]===a-1){if(a===i){g.push(k);h[k]=0}else{h[k]=a}}else if(a===0){h[k]=0}}}return g} |
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
| //ES6 | |
| function spiral(matrix) { | |
| const arr = []; | |
| while (matrix.length) { | |
| arr.push( | |
| ...matrix.shift(), | |
| ...matrix.map(a => a.pop()), | |
| ...(matrix.pop() || []).reverse(), | |
| ...matrix.map(a => a.shift()).reverse() |
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 plusplus(orig_x){ | |
| let orig_x_changed = Number(orig_x); | |
| x = orig_x_changed + 1; | |
| return orig_x_changed; | |
| } | |
| let x = '2'; | |
| plusplus(x); // 2 | |
| x; // 3 |
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 checkSign(x){ | |
| return x !== 0 ? Math.sign(x) : Object.is(x, -0) ? -1 : 1; | |
| } | |
| checkSign(-0) // -1 i.e. -ve sign | |
| checkSign(0) // 1 i.e. +ve sign | |
| checkSign(-6) // -1 | |
| checkSign(6) // 1 | |
| credits: Kyle Simpson (getify) |
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
| if (!Object.is) { | |
| Object.is = function ObjectIs(x, y) { | |
| if (x === y) { | |
| return x !== 0 || 1/x === 1/y | |
| } else { | |
| return x !== x && y !== y; | |
| } | |
| } | |
| } |