sp-answer
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

node-sp-answer

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 (< 65) {
    answer.positive = true;
  } else {
    answer.positive = false;
  }
 
  if (< 75) {
    answer.popular = true;
  } else {
    answer.popular = false;
  }
 
  answers.push(answer);
}
 
const result = spAnswer({ answers });
// result.answer === false

Dependencies (0)

    Dev Dependencies (7)

    Package Sidebar

    Install

    npm i sp-answer

    Weekly Downloads

    7

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    36 kB

    Total Files

    24

    Last publish

    Collaborators

    • arafathusayn