Prism · Structure

$case

Branches. They are tried in order: the first whose when is truthy gives its then, and else answers when none is.

The source
{ score: 87 }
The config
{
  $case: {
    branches: [
      {
        when: { $gte: [{ $ref: '$.score' }, { $const: 90 }] },
        then: { $const: 'A' },
      },
      {
        when: { $gte: [{ $ref: '$.score' }, { $const: 80 }] },
        then: { $const: 'B' },
      },
      {
        when: { $gte: [{ $ref: '$.score' }, { $const: 70 }] },
        then: { $const: 'C' },
      },
    ],
    else: { $const: 'F' },
  },
}
What comes out
'B'
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.