step()

·view .md ↗·chatgpt ↗·claude ↗

Code

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

Parameters

ParameterDescription
thresholdThreshold determining the jump.
valueValue to evaluate.

Nuxt Example

<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>Current score: {{ score }}</p>
  <p :class="status ? 'status--ok' : 'status--warn'">
    {{ status ? 'Passed' : 'Review' }}
  </p>
</template>

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

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

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