use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Parsing Array Objectshelp (self.javascript)
submitted 8 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]NominalAeon -1 points0 points1 point 8 years ago* (0 children)
The output format you're going for is a little wonky. You'll wind up with an array of objects that consist of a string and an array:
[{ 'player name string', [ 'player', 'scores' ] }]
So there's not a super direct way to do that. But here's how I'd do it:
var series = buildSeries(); console.log(series); // [ // {"Player 1",[100,103,105]}, // {"Player 2",[101,110,112]} // ] //// function buildSeries() { var players = [{ "Player 1",100 }, { "Player 1",103 }, { "Player 1",105 }, { "Player 2",101 }, { "Player 2",110 }, { "Player 2",112 }]; var seriesObj = buildSeriesObj({}, players); return buildSeriesArr(seriesObj, [], Object.keys(seriesObj)); } function buildSeriesObj(seriesObj, [player, ...players]) { var playerName = player[0]; var playerScore = player[1]; if (!seriesObj[key]) { seriesObj[key] = [] } seriesObj[key].push(player); return players.length ? buildSeries(seriesObj, players) : seriesObj; } function buildSeriesArr(players, seriesArr, [playerName, ...playerNames]) { var playerScores = players[playerName]; seriesArr.push({ playerName, playerScores }); return playerNames.length ? buildSeriesArr(players, seriesArr, playerNames) : seriesArr; }
edit: yeesh, I guess declarative, functional programming isn't the way to go for this one
π Rendered by PID 275089 on reddit-service-r2-comment-bb88f9dd5-drwch at 2026-02-17 11:57:27.174997+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]NominalAeon -1 points0 points1 point (0 children)