首页 > 其他 > 详细

氦图面试题目Boolean search

时间:2021-05-11 22:22:14      阅读:23      评论:0      收藏:0      [点我收藏+]
# 
# 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))

 

氦图面试题目Boolean search

原文:https://www.cnblogs.com/dzqdzq/p/14756732.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!