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
| let mySet = new Set([1,2, 3, 4, 5]); | |
| var filtered = [...mySet].filter((x) => x > 3) // [4, 5] |
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
| let arr = [1, 1, 2, 2, 3, 3]; | |
| let deduped = [...new Set(arr)] // [1, 2, 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
| let object1 = { a:1, b:2,c:3 } | |
| let object2 = { b:30, c:40, d:50} | |
| let merged = {…object1, …object2} //spread and re-add into merged | |
| console.log(merged) // {a:1, b:30, c:40, d:50} |
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
| var car = { | |
| model: 'bmw 2018', | |
| engine: { | |
| v6: true, | |
| turbo: true, | |
| vin: 12345 | |
| } | |
| } | |
| const modelAndVIN = ({model, engine: {vin}}) => { |
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
| let {_internal, tooBig, ...cleanObject} = {el1: '1', _internal:"secret", tooBig:{}, el2: '2', el3: '3'}; | |
| console.log(cleanObject); // {el1: '1', el2: '2', el3: '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
| var cars = ['BMW','Benz', 'Benz', 'Tesla', 'BMW', 'Toyota']; | |
| var carsObj = cars.reduce(function (obj, name) { | |
| obj[name] = obj[name] ? ++obj[name] : 1; | |
| return obj; | |
| }, {}); | |
| carsObj; // => { BMW: 2, Benz: 2, Tesla: 1, Toyota: 1 } |
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
| //Returns 0 if balanced. | |
| const isParensBalanced = (str) => { | |
| return str.split('').reduce((counter, char) => { | |
| if(counter < 0) { //matched ")" before "(" | |
| return counter; | |
| } else if(char === '(') { | |
| return ++counter; | |
| } else if(char === ')') { | |
| return --counter; | |
| } else { //matched some other char |
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 numbers = [10, 20, 30, 40]; | |
| const doubledOver50 = numbers.reduce((finalList, num) => { | |
| num = num * 2; //double each number (i.e. map) | |
| //filter number > 50 | |
| if (num > 50) { | |
| finalList.push(num); | |
| } |
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 required = () => {throw new Error('Missing parameter')}; | |
| //The below function will trow an error if either "a" or "b" is missing. | |
| const add = (a = required(), b = required()) => a + b; | |
| add(1, 2) //3 | |
| add(1) // Error: Missing parameter. |
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
| " Make IE Better Compatible " | |
| <!--[if IE]> | |
| <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
| <![endif]--> | |
| ====================================================== | |
| IE6 Only | |
| ================== | |
| _selector {...} |