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
| // Generic type for: {[key: string]: Type<any>} | |
| type kv<K extends PropertyKey, V = unknown> = { | |
| [key in K]: V; | |
| }; | |
| export declare interface Type<T> extends Function { | |
| new (...args: any[]): T; | |
| } | |
| class ClassA{ |
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 i = [0,1,2,3,4]; | |
| const r = i.map((v) => [v * 2 , (v*2)+1]); | |
| console.log([].concat(...r)); | |
| // output: [0,1,2,3,4,5,6,7,8,9] |
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 s = new Map(); | |
| var o = {id:1, name:"test"} | |
| var o1 = {...o, id:2} | |
| var o2 = o; | |
| var arr = [o,o1,o2]; | |
| arr.forEach(element => { | |
| s.set(element.id, element); | |
| }); |
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 arr = [{ site_id: 1, col:[] }, { site_id: 1 }, { site_id: 1 }, { site_id: 2 }, { site_id: 1 }, { site_id: 3 }]; | |
| const obj = arr.reduce((acc, item) => { | |
| acc[item.site_id] = item; | |
| return acc; | |
| }, {}); | |
| console.log(Object.values(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
| static void BubbleSort() | |
| { | |
| int[] nums = new int[] { 5, 1, 7, 6, 4, 2, 8, 3 }; | |
| for (int i = nums.Length; i > 0; i--) | |
| { | |
| for (int j = 0; j < i - 1; j++) | |
| { | |
| if (nums[j + 1] < nums[j]) | |
| { | |
| int t = nums[j]; |
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
| static int Pgcd(int a, int b) | |
| { | |
| //return euclide(a, b); | |
| return egyptienne(a, b); | |
| } | |
| static int euclide(int a, int b) | |
| { | |
| if (a > b) | |
| { |
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
| static List<double> NombresDeArmstrong() | |
| { | |
| // uniquement les nombres de 100 à 999 | |
| List<double> results = new List<double>(); | |
| int n = 99; | |
| double somme = 0; | |
| string s; | |
| for (int i = 0; i < 1000; i++) | |
| { | |
| 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
| // require all `test/**/*.js` | |
| const testsContext = require.context('./', true, /.+spec.js\b/); | |
| testsContext.keys().forEach(testsContext); |
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
| // time complexity : O(n) | |
| function isTextPalindrome(text){ | |
| if(text === undefined) return false; | |
| let left = 0; | |
| let right = text.length - 1; | |
| while(left < right){ | |
| if(text[left++] !== text[right--]){ | |
| return false; | |
| } |
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 f = {folder:{id:1, name:'description'}}; | |
| let o:{id?:number, name?:string} = {}; | |
| (o) = (f && f['folder'])?{...f['folder']}:{}; | |
| console.log(o); |
NewerOlder