获取分数列表

时间:2016-01-22 15:48:53

标签: javascript arrays

我正在尝试创建一个数字列表,以便我可以通过assignGrade函数传递它。我想把它们放在一个数组中,然后运行它们得到A,B,C,D,F的结果。我认为我很接近,但不知道还有什么可以尝试。

drop table if exists lr_words;

create table lr_words
(
    word varchar(300)
);

insert into lr_words(word) values ('my_key');

drop function if exists lr_encrypt;
delimiter $$
create function lr_encrypt(p_text varchar(1000) character set UTF8)
   returns varbinary(200)
begin

    declare l_word varchar(300) default '';
    declare l_key_length int default 512;

    select word
      into l_word  
      from lr_words;

    return aes_encrypt(p_text, SHA2(l_word,l_key_length));

end
$$

drop function if exists lr_decrypt;
delimiter $$
create function lr_decrypt(p_text varbinary(200))
   returns text character set UTF8
begin

    declare l_word varchar(300) default '';
    declare l_key_length int default 512;

    select word
      into l_word  
      from lr_words;

    return cast(aes_decrypt(p_text, SHA2(l_word,l_key_length)) AS char(1000));

end
$$

select lr_encrypt(email) as email_en, 
lr_decrypt(lr_encrypt(email)) as email_dec
from my_table

2 个答案:

答案 0 :(得分:0)

你非常接近,你只需要改变一些事情

var assignGrade = function assignGrade(score) {
    if (score > 90) {
        return 'A';
    } else if (score > 80) {
        return 'B';
    } else if (score > 70) {
        return 'C';
    } else if (score > 65) {
        return 'D';
    } else {
        return 'F';
    }
}

function getScore(result) {
    //result = []; <- no to format array
    for (var i = 0; i < result.length; i++) {
         //https://jsfiddle.net/0m8e670q/1/ you have just called the function with no value and didnt store the returned value
         result[i] = assignGrade(result[i]);//you need to send the function a value and then store it
    }
    return result;
}

console.log(getScore([55,77,88]));//send array

小提琴 - https://jsfiddle.net/0m8e670q/1/

答案 1 :(得分:0)

是的,你关闭了,但有很多小错误:

var assignGrade = function assignGrade(score) {
    if (score > 90) {
        return 'A';
    } else if (score > 80) {
        return 'B';
    } else if (score > 70) {
        return 'C';
    } else if (score > 65) {
        return 'D';
    } else {
        return 'F';
    }
}

function getScore(input) {
    result = [];
    for (var i = 0; i < input.length; i++) {
        result.push(assignGrade(input[i]));
    }
    return result;
}

console.log(getScore([55,77,88]));

您将获得["F", "C", "B"]