列表

详情


FED40. 搜索数字

描述

请补全JavaScript函数,要求以boolean的形式返回字符串参数中是否包含数字。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1735ms, 内存消耗: 77860KB, 提交时间: 2021-12-07

{"css":"","js":"function _search(string) {\n    // 补全代码\n    //return [..string].find(c => Number(c) === 0 ? false : true);\n    return string.search(/[0-9]/) >= 0 ? true : false;\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1738ms, 内存消耗: 77772KB, 提交时间: 2021-12-26

{"css":"","js":"function _search(string) {\n    var reg=/\\d+/\n    return reg.test(string)  \n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1738ms, 内存消耗: 77772KB, 提交时间: 2021-12-15

{"css":"","js":"function _search(string) {\n    // 补全代码\n    return string.search(/\\d/) > -1\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1738ms, 内存消耗: 77772KB, 提交时间: 2021-12-09

{"css":"","js":"function _search(string) {\n    // 补全代码\n    for (let i = 0; i < string.length; i++) {\n      if (string[i] >= '0' && string[i] <= '9') {\n        return true;\n      }\n    }\n    return false;\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1738ms, 内存消耗: 77804KB, 提交时间: 2021-12-15

{"css":"","js":"function _search(string) {\n    // 补全代码\n    var n = string.search(/\\d/);\n    if(n == -1){\n        return false;\n    } else {\n        return true;\n    }\n}","html":"","libs":[]}

上一题