Fe-interview: [js] 第370天 对`a == ('1'||'2'||'3') ? false : true`写法进行改进,写出你优化后的方法

Created on 19 Apr 2020  ·  4Comments  ·  Source: haizlin/fe-interview

第370天 对a == ('1'||'2'||'3') ? false : true写法进行改进,写出你优化后的方法

我也要出题

js

Most helpful comment

![1,2,3].includes(+a)
or
!['1', '2', '3'].includes(a + '')
or
!{1: true, 2: true, 3: true}[a]

All 4 comments

![1,2,3].includes(+a)
or
!['1', '2', '3'].includes(a + '')
or
!{1: true, 2: true, 3: true}[a]

  1. a == ('1' || '2' || '3')
  2. ![1, 2, 3].includes(Number(a)) or !['1', '2', '3'].includes(String(a))

!/^[1|2|3]$/.test(a)

@ferrinweb

![1,2,3].includes(+a)
or
!['1', '2', '3'].includes(a + '')
or
!{1: true, 2: true, 3: true}[a]

三种写法!

Was this page helpful?
0 / 5 - 0 ratings