Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.14 KB

how-many-e-mails-we-sent-today.md

File metadata and controls

45 lines (31 loc) · 1.14 KB

How many e-mails we sent today? 7 Kyu

LINK TO THE KATA - FUNDAMENTALS LOGIC MATHEMATICS

Description

Every day we can send from the server a certain limit of e-mails.

Task:

Write a function that will return the integer number of e-mails sent in the percentage of the limit.

Example:

limit       - 1000;
emails sent - 101;
return      - 10%; // because integer from 10,1 = 10

Arguments:

  • sent: number of e-mails sent today (integer)
  • limit: number of e-mails you can send today (integer)

When:

  • the argument sent = 0, then return the message: "No e-mails sent"
  • the argument sent >= limit, then return the message: "Daily limit is reached"
  • the argument limit is empty, then default limit = 1000 emails;

Solution

const getPercentage = (sent, limit = 1000) => {
  if (sent === 0) return 'No e-mails sent'
  if (sent >= limit) return 'Daily limit is reached'

  return `${Math.trunc((sent * 100) / limit)}%`
}