step()

·veu .md ↗·chatgpt ↗·claude ↗

Codi

function step(threshold: number, value: number): number {
    return value < threshold ? 0 : 1;
}

Paràmetres

ParàmetreDescripció
thresholdLlindar que determina el salt.
valueValor a avaluar.

Exemple amb Nuxt

<script setup lang="ts">
const step = (threshold: number, value: number) =>
  (value < threshold ? 0 : 1)

const minScore = 70
const score = ref(50)
const status = computed(() => step(minScore, score.value))
</script>

<template>
  <input type="range" min="0" max="100" v-model.number="score" />
  <p>Puntuació actual: {{ score }}</p>
  <p :class="status ? 'status--ok' : 'status--warn'">
    {{ status ? 'Apte' : 'Revisa' }}
  </p>
</template>

<style scoped>
input[type="range"] {
  width: 100%;
  margin-bottom: 0.75rem;
}

.status--ok {
  color: #16a34a;
}

.status--warn {
  color: #dc2626;
}
</style>