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
| // non-functional approach | |
| const nums = [1, 2, 3] | |
| let total = 0 | |
| for (let i = 0; i < nums.length; i++) { | |
| total += nums[i] | |
| } | |
| console.log(total) // => 6 | |
| // functional recursive approach |
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 array = [1, 2, 3, 4, 5, 1]; | |
| # filter unique values | |
| const newArray = [...new Set(array)]; | |
| // Result: [1,2,3,4,5] | |
| # convert to boolean | |
| const iTrue = !0; | |
| const alsoFalse = !!0; | |
| // Result: true |
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
| <div id="counter"></div> | |
| <script> | |
| var n = localStorage.getItem('on_load_counter'); | |
| if (n === null) { | |
| n = 0; | |
| } | |
| n++; |
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
| class App extends React.Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| isLoggedIn: false | |
| } | |
| } | |
| toggleAuth = () => { |
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 useCustomHooks() { | |
| let userName = "Anil Kumar"; | |
| let userDesignation = "Coder"; | |
| return [userName, userDesignation]; | |
| } | |
| function ApplicationComponent() { | |
| const [name, designation] = useCustomHooks(); | |
| return ( | |
| <div> |
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
| .parent{ | |
| position: relative; | |
| height: 100px; # 100vh | |
| width: 100px; # 100vw | |
| border: 1px solid red; | |
| } | |
| .child{ | |
| position: absolute; | |
| border: 1px solid green; |
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 calculator = { | |
| result: 0, | |
| one: function () { | |
| this.result = this.result + 1; | |
| return this; | |
| }, | |
| three: function () { | |
| this.result = this.result + 3; | |
| return this; | |
| }, |
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 obj = { | |
| result: 0, | |
| addNumber: function (a, b) { | |
| this.result = a + b; | |
| return this; | |
| }, | |
| multiplyNumber: function (a) { | |
| this.result = this.result * a; | |
| return this; | |
| }, |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <button id="myBtn">fetch it</button> | |
| <script> |
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 rearrange_pos_negative(arr) { | |
| var i, j; | |
| j = 0; | |
| for (i = 0; i < arr.length; i++) { | |
| if (arr[i] < 0) { | |
| if (i != j) { | |
| var temp = arr[i]; | |
| arr[i] = arr[j]; | |
| arr[j] = temp; | |
| } |
NewerOlder