1.0.4 • Published 4 years ago

sp-answer v1.0.4

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

node-sp-answer

npm.io npm.io npm.io npm.io npm.io

Determine the surprisingly popular answer

npm i sp-answer

Description

function spAnswer(parameters: {
  question?: Question; // optional
  answers: Answer[]; // required
  threshold?: number; // default: 0
}): SurprisinglyPopularAnswer | null {
  /* ... */
}

interface Question {
  id?: string; // optional
  text: string;
}

interface Answer {
  positive: boolean | string;
  popular: boolean | string;
}

interface SurprisinglyPopularAnswer {
  answer: boolean | string | string[];
  question?: Question; // optional
}

Example

// Question: Is Philadelphia the capital of Pennsylvania?
const spAnswer = require("sp-answer");

let answers = [];

for (let i = 0; i < 100; i++) {
  let answer = {
    positive: true,
    popular: true,
  };

  if (i < 65) {
    answer.positive = true;
  } else {
    answer.positive = false;
  }

  if (i < 75) {
    answer.popular = true;
  } else {
    answer.popular = false;
  }

  answers.push(answer);
}

const result = spAnswer({ answers });
// result.answer === false
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago