
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
@nrk/valg-valgomat-algoritme
Advanced tools
The algorithm used to calculate distance between sets of positions for NRKs Valgomat
Calculate the proximity of two sets of positions.
Calculates the proximity of two sets of positions. Mostly used to calculate the proximity of various party positions and a voter position.
The simple case is comparing to sets of positions.
import { proximity } from '@nrk/valg-valgomat-algoritme'
let partyPositions = {
id1: 1,
id2: -1
}
let voterPositions = {
id1: -2,
id2: 2
}
let p = proximity(partyPositions, voterPositions)
// => 0.25
The module also comes with a function to compare many positions to one position.
import { proximityMap } from '@nrk/valg-valgomat-algoritme'
let partyAPositions = {
id1: 1,
id2: -1
}
let partyBPositions = {
id1: 2,
id2: -2
}
let partyPostitions = {
partyA: partyAPositions,
partyB: partyBPositions
}
let voterPositions = {
id1: null,
id2: -2
}
let proximities = proximityMap(voterPositions, partyPositions)
// => { "partyA": 0.75, "partyB": 1.0 }
import { proximity, proximityMap } from '@nrk/valg-valgomat-algoritme'
Accepts two sets of positions and returns the proximity between them.
Positions are given in the form of sets:
{
[statement: string]: -2 | -1 | 1 | -2 | null
}
Output will be a number in the interval [0.0, 1.0] where 0.0 is the furthest away and 1.0 is the closest possible proximity (iow. identical).
If we are unable to determine a proximity, the output will be null. This happens if we are comparing a pair of vectors where one of the vectors are empty or there are no overlapping statements.
Accepts a set of positions and a map of many sets of positions and returns a map of the proximities between a position in the position map and the first position.
This is useful if you want to calculate the proximity of one set of positions and many sets of positions. For instance between all parties and a single voter.
Output will be a map from the keys in the positionsMap and the proximity to the given position.
npm install @nrk/valg-valgomat-algoritme
FAQs
The algorithm used to calculate distance between sets of positions for NRKs Valgomat
We found that @nrk/valg-valgomat-algoritme demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 183 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.