我只是在一个简单的面试问题上挣扎:请反转一个单独的链接列表.
虽然我未能及时提供工作答案以保存采访,但之后我能够提出解决方案.
我的解决方案是否正确 你怎么用Big-Oh分析这个?是否有更有效的方法来反转单链表?
// reverse a linked list
var reverseLinkedList = function(linkedlist) {
var node = linkedlist;
var previous = null;
while(node) {
// reverse pointer
node.next = previous;
// increment previous to current node
previous = node;
// increment node to next node
if (node.next){
node = node.next
} else {
node = null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意:在我搜索类似帖子时,我确实在JavaScript中找到了一个示例.我想知道我的代码是否可行(没有temp变量).谢谢.
在下面的代码中使用as或 有什么区别<>?
选项 A - 使用 'as' 作为返回值
convertResultToParams(columnView:IColumnViewResult):IColumnViewParams {
const params = {};
Object.keys(this.getDefaultParams())
.map(key => params[key] = columnView[key]);
return params as IColumnViewParams;
}
Run Code Online (Sandbox Code Playgroud)
选项 B - 使用“括号”作为返回值
convertResultToParams(columnView:IColumnViewResult):IColumnViewParams {
const params = {};
Object.keys(this.getDefaultParams())
.map(key => params[key] = columnView[key]);
return <IColumnViewParams>params;
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能在变量声明中声明类型?
如何createSpyObj从茉莉花中导入属性?
我已经安装@types/jasmine并jasmine-core通过 npm安装。
我尝试将茉莉花导入为:
import jasmine from 'jasmine;
import { createSpyObj } from 'jasmine'; //triggers import error in IDE
import * as jasmine from 'jasmine'; //triggers import error in IDE
Run Code Online (Sandbox Code Playgroud)
这些都不允许我访问createSpyObjWebStorm IDE 中不会抛出错误。
更多信息:
我createSpyObj在打字文件中看到了命名空间声明。它嵌套在jasmine命名空间中。这与expect,不同,it它们是全局声明,但我不应该能够使用它访问它jasmine.createSpyObj吗?
相关,但不重复
如何计算阵列的总量?
我将数据传递给子组件作为prop,我被困在这里.当我控制日志道具时,它返回一个非常复杂的对象.我试过this.values.reduce()功能,但它不起作用.
<template>
<tr v-for="value in values" >
<th scope="row">{{$index+1}}</th>
<td>{{value.name}}</td>
<td>-</td>
<td>${{value.total}}</td>
</tr>
<tr>
<th></th>
<td><strong>Total:{{total}}</strong></td>
<td>-</td>
<td>-</td>
</tr>
</template>
<script>
export default {
props: ['values'],
ready: function() {
}
}
</script>
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Web应用程序安装打字稿键入,但无法获得命令提示符以识别该typings命令。
typings install 引发以下错误:
'typings' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
当我运行时npm i typings -g,控制台会告诉我模块已安装。但是当我查看全局npm目录时,没有打字文件。
C:\gitdev\MyWebApp\src\main\webapp\myUI>npm i typings -g
C:\home\123456\AppData\Roaming\npm\typings -> C:\home\123456\AppData\Roaming\npm\node_modules\typings\dist\bin.js
C:\home\123456\AppData\Roaming\npm
`-- typings@2.1.1
Run Code Online (Sandbox Code Playgroud)
123456为了安全起见,我的用户名已被替换为。其他所有内容均逐字复制。
我没有管理员权限(我在工作计算机上)
where typings 还会引发错误(信息:找不到给定模式的文件。
npm -g对于grunt-cli效果很好
npm在我的PATH中 C:\Users\123456\AppData\Roaming\npm
我正在用的打字稿(耶)角1.5,我们既包括@types/angular和@types/angular-mocks。
麻烦的是,@types/angular-mocks列出@types/angular与*版本的依赖。这会导致纱线在上安装1.6 @types/angular-mocks/node_modules。
最终的结果是TS编译错误:@types/angular1.5有$注射比不同的定义@types/angular1.6
如何使tsconfig忽略@types/angular-mocks/node_modules?
这是我当前的tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"es2016",
"dom"
],
"rootDir": "app/modules",
"mapRoot": "/modules/",
"sourceRoot": "/modules",
"typeRoots": ["./node_modules/@types"],
"baseUrl": ".",
"paths": {
"*": [
"app/modules/*"
]
}
},
"include": [
"./node_modules/@types",
"./typings-custom/*.d.ts"
],
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud) 我遇到了一种情况,其中类型定义node_modules/@types正在安装自己的@types依赖项,而这些“嵌套的” @types与我的顶级@types冲突。
@types
|-angular //v1.5
|-angular-ui-bootstrap
|-node_modules
|-@types
|-angular //v1.6
Run Code Online (Sandbox Code Playgroud)
node_modules/@types/**/node_modules在tsconfig中?一个警告-我正在使用awesome-typescript-loader,这可能有一些限制。
我尝试过的
1- exclude属性中的文件glob 排除嵌套的node_modules
compilerOptions.exclude: '../node_modules/@types/**/node_modules'
Run Code Online (Sandbox Code Playgroud)
2- types明确声明
compilerOptions.types: ['angular', 'angular-ui-bootstrap']
Run Code Online (Sandbox Code Playgroud)
3-文件中的glob typeRoots排除嵌套的node_modules
compilerOptions.typeRoots: ['../node_modules/@types/**/!(node_modules)']
Run Code Online (Sandbox Code Playgroud)
我学到了什么
1-排除似乎不适用于@types
2-使用“类型”包含类型意味着包含其依赖的@types
3-typeRoots似乎不适用于文件glob(或者我写的glob错误)
有关:
https://github.com/Microsoft/TypeScript/issues/9731
https://github.com/Microsoft/TypeScript/issues/11917
https://github.com/s-panferov/awesome-typescript-loader/issues/492
tsconfig - 如何忽略一个特定的目录@类型/不管/ node_modules?
有关我的环境的详细信息
“ node”:“ 8.6.0”,“ typescript:” 2.8.3“,” awesome-typescript-loader“:” 5.0.0“,” webpack“:” 4.8.3“,
我正在尝试编写一个基于Express构建的行程应用程序.Swig是模板引擎.我对Swig的自动景观功能感到困惑.它到底是做什么用的?
Swig 文档示例:
"Control auto-escaping of variable output from within your templates."
// myvar = '<foo>';
{% autoescape true %}{{ myvar }}{% endautoescape %}
// => <foo>
{% autoescape false %}{{ myvar }}{% endautoescape %}
// => <foo>
Run Code Online (Sandbox Code Playgroud)
我的代码:
<script>
{% autoescape false %}
var all_hotels = {{ hotels | json }};
var all_restaurants = {{ restaurants | json }};
var all_things_to_do = {{ things_to_do | json }};
{% endautoescape %}
</script>
Run Code Online (Sandbox Code Playgroud)
谢谢.
使用类型强制(==而非===)检查未定义/空值是否可以接受?
不利之处是什么?有没有更好的方法来检查未定义/空值?
澄清:我正在寻找一条将同时检查undefined和null的语句。
test(null);
test(undefined);
function test(myVar) {
if (myVar != undefined) {
alert('never gets called')
}
}
Run Code Online (Sandbox Code Playgroud) 我看过很多关于如何在单元测试中使用 async/await 的文章,但我的需求正好相反。
您如何为使用 async/await 的方法编写测试?
我的规范在“等待”行之后无法访问任何代码。具体来说,规范在两个方面失败。
1)HelloWorld.otherCall返回 undefined 而不是我指定的返回值
2)HelloWorld.processResp永远不会被调用
class HelloWorld {
async doSomething(reqObj) {
try {
const val = await this.otherCall(reqObj);
console.warn(val); // undefined
return this.processResp(val);
}
}
}
describe('HelloWorld test', function () {
let sut = new HelloWorld(); //gross simplification for demo purposes
describe('doSomething()', function () {
beforeEach(function mockInputs() {
this.resp = 'plz help - S.O.S.';
});
beforeEach(function createSpy() {
spyOn(sut, 'otherCall').and.returnValue( $q.resolve(this.resp) );
spyOn(sut, 'processResp');
});
it('should call otherCall() with proper …Run Code Online (Sandbox Code Playgroud) angularjs ×4
typescript ×4
jasmine ×2
javascript ×2
express ×1
linked-list ×1
node.js ×1
npm ×1
npm-install ×1
tsconfig ×1
unit-testing ×1
vue.js ×1
webpack ×1
webstorm ×1
yarnpkg ×1