Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var array = ["Kristine", "Inocencia", "Ayako", "Olin", "Nguyet", "Esteban", "Tai"]
- var prefix = []
- var suffix = []
- array.forEach(function(value, index) {
- prefix.push(value[0])
- suffix.push(value[value.length - 1].toUpperCase())
- })
- var pos = 0
- prefix.forEach(function(pre, index1) {
- var count = 0
- suffix.forEach(function(suf, index2) {
- if (pre == suf) {
- count++
- }
- })
- if (count == 0) {
- pos = index1
- }
- })
- var res = []
- res.push(array[pos])
- while(res.length < prefix.length) {
- prefix.forEach(function(value, index) {
- if (res[res.length - 1][res[res.length - 1].length - 1].toUpperCase() == value && res.length < prefix.length) {
- res.push(array[index])
- }
- })
- }
- console.log(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement