0

I'm trying to get a list of instagram accounts that I follow but they dont follow me back. Follow returns a list of people that I follow and followed does return a list of people that follow me. And I want to remove followed from follow to get all of those who dont follow me back. But filtering myArray doesn't change it's content. It seems like its elements are in different format so it cant compare them yet they are both arrays with usernames. I've tried many methods of filtering the list but they all give the same result.

EDIT: eg. of array is: 0: "xxx" 1: "yyy" 2: "zzz"



function follow(url){
    var list=[];
    var Httpreq = new XMLHttpRequest(); 
    Httpreq.open("GET",url,false);
    Httpreq.send(null);
var json_obj = JSON.parse(Httpreq.responseText);
for (const node of json_obj.data.user.edge_follow.edges) {
         list.push(String(node.node.username));
        }

        return list;

}

function followed(url){
    var list=[];
    var Httpreq = new XMLHttpRequest(); 
    Httpreq.open("GET",url,false);
    Httpreq.send(null);
var json_obj = JSON.parse(Httpreq.responseText);
for (const node of json_obj.data.user.edge_followed_by.edges) {
         list.push(String(node.node.username));

        }

        return list;

}

var myArray=new Array(follow(urlFollow));

wait(5000);

var toRemove=new Array(followed(urlFollowed));

var myArray = myArray.filter((item) => !toRemove.includes(item));
console.log(myArray)
13
  • the contents of the array are of string type or not ? Commented Nov 2, 2019 at 14:17
  • The type of it is undefined, and when I try to print a single element with alert(myArray[1]) im getting undefined also. Commented Nov 2, 2019 at 14:27
  • can you check the content of the array, i mean the entire array Commented Nov 2, 2019 at 14:27
  • I've checked it with typeof. The output is: object Commented Nov 2, 2019 at 14:39
  • what are the contents of the object Commented Nov 2, 2019 at 14:39

1 Answer 1

1

I have added the both cases where the array contains of data of string type and the other way if it contains Object type as mentioned in EDIT

//assuming the array contains the data of string type
let follow = ['a','b','c','d']
let followed = ['b','d','e']

follow = new Set(follow)
followed = new Set(followed)
let difference1 = new Set([...follow].filter(x => !followed.has(x)))
console.log(Array.from(difference1))



//assuming the array contains the data of object type
let follow1 = [{0:'a'},{1:'b'},{2:'c'},{3:'d'}]
let followed1 = [{0:'b'},{1:'d'},{2:'e'}]

let values = followed1.map(elem => Object.values(elem))
values = Array.from(new Set(values.flat()))

let diff1 = follow1.filter((elem,index) => !values.includes(elem[index]))
console.log(diff1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.