我有几个像这样的50多个名字的数组.
["dan", "ryan", "bob", "steven", "corbin"]
["bob", "dan", "steven", "corbin"]
Run Code Online (Sandbox Code Playgroud)
我有另一个具有正确顺序的数组.请注意,上面的第二个数组不包含所有名称,但我仍然希望它遵循以下顺序:
["ryan", "corbin", "dan", "steven", "bob"]
Run Code Online (Sandbox Code Playgroud)
它没有逻辑顺序,它们只是按此顺序排列.对我来说有意义的是将每个数组与正确排序的数组进行比较.我想我看到有些人用PHP做这件事,但我找不到JavaScript解决方案.有谁知道怎么做?我已经尝试了几个小时,我很难过.
我有我们的员工在json文件中,并有想法使用ES6类的数据.我越用这个工作,我就越觉得我可能会遗漏一些东西.我这样做是在coffeescript中工作的:
fetch = require('node-fetch')
domain = 'domain.com'
apiSrc = 'api.domain.com'
slug = 'people'
class Person
constructor: (json) -> {name: @name, title: @title, school: @school, bio: @bio} = json
email: (username) ->
username.replace(/\s/, '.').toLowerCase() + '@' + domain
profile: ->
content = []
if this.name then content.push("#{@name}")
if this.title then content.push("#{@title}")
if this.school then content.push(school) for school in "#{@school}"
if this.bio then content.push("#{@bio}")
if this.name then content.push(this.email("#{@name}"))
content.join('')
fetch('http://' + apiSrc + '/' + slug + '.json')
.then((response) -> response.json())
.then((api) …Run Code Online (Sandbox Code Playgroud)