我试图找出数组中的总和等于给定输入的最小元素。我尝试了很少的输入总和,但在第一种情况下只能找到一对,而我需要实现的不仅仅是一对。
var arr = [10, 0, -1, 20, 25, 30];
var sum = 45;
var newArr = [];
console.log('before sorting = ' + arr);
arr.sort(function(a, b) {
return a - b;
});
console.log('after sorting = ' + arr);
var l = 0;
var arrSize = arr.length - 1;
while (l < arrSize) {
if (arr[l] + arr[arrSize] === sum) {
var result = newArr.concat(arr[l], arr[arrSize]);
console.log(result);
break;
} else if (arr[l] + arr[arrSize] > sum) {
arrSize--;
} else { …Run Code Online (Sandbox Code Playgroud)这是编译应用程序时的错误。我的@ angular / cli:1.2.4版本
@ angular / cli:1.2.4
节点:8.11.1
os:win32 x64
@ angular / animations:4.3.6
@ angular / common:4.3.6
@ angular / compiler:4.3.6
@ angular / core:4.3.6
@角/形式:4.3.6
@角/ http:4.3.6
@角/平台-浏览器:4.3.6
@角/平台-浏览器-动态:4.3.6
@角/路由器:4.3.6
@角/编译器- cli:4.3.6
@ angular / cli:1.2.4
@ angular /语言服务:4.3.6
This is the error while compiling the application.
ERROR in ./~/css-loader?{"sourceMap":false,"importLoaders":1}!./~/postcss-loader?{"ident":"postcss"}!./src/styles.css
Module build failed: BrowserslistError: Unknown browser query `dead`
at error (C:\Github project\angForm\node_modules\browserslist\index.js:37:11)
at C:\Github project\angForm\node_modules\browserslist\index.js:222:9
at Array.forEach (<anonymous>)
at browserslist (C:\Github project\angForm\node_modules\browserslist\index.js:196:13)
at Browsers.parse (C:\Github project\angForm\node_modules\autoprefixer\lib\browsers.js:44:14)
at …Run Code Online (Sandbox Code Playgroud) onDelete(name) {
console.log("ProductList.onDelete: ", name);
let {products} = this.state;
products = products.filter(product => product.name !== name);
this.setState({products});
localStorage.setItem('products', JSON.stringify(products));
}
Run Code Online (Sandbox Code Playgroud)