Is it possibile to use an inline return with javascript map
function?
Instead of doing
array.map(token => { var x=new Object(); x[token]=words[token]; return x;} )
I would like to do it inline as doing
array.map(token => token )
so applying a inline method like
array.map(token => inline_function(token) )
I have tried like
Object.keys(chart).sort((a,b) => words[b]-words[a]).map(token => ( (token) => (new Object())[token]=words[token] )(token) )
but cannot get the return using a anonymous call with ()
.
Here is an example using the non inline case:
text = "Lorem ipsum dolor sit amet,\n consectetur adipiscing elit,\nsed do eiusmod tempor incididunt\nut labore et dolore magna aliqua.\nUt enim ad minim veniam,\nquis nostrud exercitation ullamco laboris nisi\nut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse\ncillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident,\nLorem ipsum dolor sit amet etwas,\nsunt in culpa qui officia deserunt mollit anim id est laborum"
words = text.split(/\s+/g)
count = words.reduce(function(m, v) {
m[v] = m[v] ? m[v] + 1 : 1;
return m;
}, {})
sorted = Object.keys(count).sort((a, b) => count[b] - count[a]).map(token => {
var x = new Object();
x[token] = count[token];
return x;
})
console.log(sorted)
I have the following code: const array = [{ a: 'a', b: 'b' }]; console.log(...array); const store = { obj: ...array } console.log will print the results just fine. However, ...
I have the following code: const array = [{ a: 'a', b: 'b' }]; console.log(...array); const store = { obj: ...array } console.log will print the results just fine. However, ...
I have a simple react component that uses react hooks. I'm using useEffect and useState. The problem is that i realized my API is getting huge amount of hits, after debugging i see that useEffect is ...
I have a simple react component that uses react hooks. I'm using useEffect and useState. The problem is that i realized my API is getting huge amount of hits, after debugging i see that useEffect is ...
I just noticed an odd cookie policy problem that only affects IE. I could only test on IE11. Perhaps you know a workaround? Step 1. This requires 2 domains. We'll call them cart.com and tracking.com. ...
I just noticed an odd cookie policy problem that only affects IE. I could only test on IE11. Perhaps you know a workaround? Step 1. This requires 2 domains. We'll call them cart.com and tracking.com. ...
WHAT I WANT TO BUILD: I have such stuff in mongo: { team1: 'Love', team2: 'Popa', score: 3 } { team1: 'Love' team2: 'Ola' score: 1 } { team1: 'Popa' team2: 'Ola' score: 5 } { ...
WHAT I WANT TO BUILD: I have such stuff in mongo: { team1: 'Love', team2: 'Popa', score: 3 } { team1: 'Love' team2: 'Ola' score: 1 } { team1: 'Popa' team2: 'Ola' score: 5 } { ...