Last active
October 22, 2019 09:30
-
-
Save tsertkov/9ba84b56ac425a708b5159e5bba76aeb to your computer and use it in GitHub Desktop.
Revisions
-
tsertkov renamed this gist
Oct 22, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tsertkov revised this gist
Oct 22, 2019 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,4 +18,9 @@ const a1 = [0, 2, 4, 6, 8, 8] const a2 = [1, 2, 3, 4, 5, 6] […new Set(a1)].filter(item => a2.includes(item)) // Unique elements const a = [0, 1, 2, 1, 1, 0] Array.from(new Set(a)) ``` -
tsertkov revised this gist
Oct 22, 2019 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,9 +13,9 @@ const a = ['blue', 'yellow'] a[(Math.floor(Math.random() * (a.length)))] // Arrays intersection const a1 = [0, 2, 4, 6, 8, 8] const a2 = [1, 2, 3, 4, 5, 6] […new Set(a1)].filter(item => a2.includes(item)) ``` -
tsertkov revised this gist
Oct 22, 2019 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,4 +12,10 @@ Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({valu const a = ['blue', 'yellow'] a[(Math.floor(Math.random() * (a.length)))] // Arrays intersection var numOne = [0, 2, 4, 6, 8, 8]; var numTwo = [1, 2, 3, 4, 5, 6]; var duplicatedValues = […new Set(numOne)].filter(item => numTwo.includes(item)); console.log(duplicatedValues); // returns [2, 4, 6] ``` -
tsertkov revised this gist
Oct 22, 2019 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,9 @@ Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({key}) => key) Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({value}) => value) // Get random value from array const a = ['blue', 'yellow'] a[(Math.floor(Math.random() * (a.length)))] ``` -
tsertkov created this gist
Oct 22, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ # JavaScript array tips & tricks ```javascript // Array mapping with .from() Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({key}) => key) Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({value}) => value) ```