Scala:for -reherehension将String转换为Map [Char,Int]

时间:2016-04-09 19:29:30

标签: scala dictionary functional-programming for-comprehension

使用for-comprehension循环遍历Scala中的String并生成一个字符映射和一个表示该字符在字符串中的次数的整数是什么好方法?

def mapString(s: String): Map[Char, Int] = {
     for(c<-s) ...
}

1 个答案:

答案 0 :(得分:0)

exports.localAuth = function (username, password) {

   return db.User.findOne({ username: username }).exec()
   .then(function (result){
      if(result){
         var hash = result._doc.passwordHash;

         if(!hash){
            console.warn("User " + username + " has no password set");
            return null;
         }
         console.log(bcrypt.compareSync(password, hash));
         if (bcrypt.compareSync(password, hash)) {
            return result;
         } else {
            return null;
         }
      } else {
         return null;
      }
   },
      function(reason){
         console.error("Failed to login: " + reason);
      }
   );
};