# # Your previous Plain Text content is preserved below: # # # Boolean search is powerful in sourcing and recruiting. # We will use machine learning prediction to provide relations among skills. Now we need a function to transfer those relations to a string with correct boolean format. # # Example1: # input: [["java", "python"], ["machine learning", "deep learning"]] # output: ("java" OR "python") AND ("machine learning" OR "deep learning") # # Example2: # input: [[["java", "maven", "spring"], "python"], ["machine learning", "deep learning"]] # output: (("java" OR "maven" OR "spring") AND "python") AND ("machine learning" OR "deep learning")
// let a = [[["java", "maven", "spring"], "python"], ["machine learning", "deep learning"]] let a = [["java", "python"], ["machine learning", "deep learning"]]; // [["java", "maven", "spring"], "python"] function subString(arr, dep=0){ if(arr.every((x)=>typeof x === 'string')){ return `(${arr.map(x=>`"${x}"`).join(' OR ')})`; } let s = arr.map(a => { if(Array.isArray(a)){ return subString(a, 1); } return `"${a}"`; }).join(' AND '); return dep ? `(${s})` : s; } console.log(subString(a))