Suppose we have an array like
var a = [
    { name: 'Tom', surname: 'TestAsIvanov' },
    { name: 'Kate', surname: 'Ivanova' },
    { name: 'John', surname: 'Alivanov' },
    { name: 'Ivan', surname: 'Ivanov' }
]
I need to sort this array by surname field based on a provided string, e.g.:
- for 'iva'the pattern array should be sorted as follows
var newA = [
    { name: 'Ivan', surname: 'Ivanov' },
    { name: 'Kate', surname: 'Ivanova' },
    { name: 'John', surname: 'Alivanov' },
    { name: 'Tom', surname: 'TestAsIvanov' },
]
- for 'a'the pattern array should be sorted as follows
var newA = [
    { name: 'John', surname: 'Alivanov' },
    { name: 'Ivan', surname: 'Ivanov' },
    { name: 'Kate', surname: 'Ivanova' },
    { name: 'Tom', surname: 'TestAsIvanov' },
]
So arrays should be ordered by string pattern provided. How is it possible to implement this?
 
     
     
    