refactor(): use const and let instead of var
This commit is contained in:

committed by
Victor Berchet

parent
73593d4bf3
commit
77ee27c59e
@ -64,15 +64,15 @@ export function and(bools: boolean[]): boolean {
|
||||
}
|
||||
|
||||
export function merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} {
|
||||
var m: {[key: string]: V} = {};
|
||||
const m: {[key: string]: V} = {};
|
||||
|
||||
for (var attr in m1) {
|
||||
for (const attr in m1) {
|
||||
if (m1.hasOwnProperty(attr)) {
|
||||
m[attr] = m1[attr];
|
||||
}
|
||||
}
|
||||
|
||||
for (var attr in m2) {
|
||||
for (const attr in m2) {
|
||||
if (m2.hasOwnProperty(attr)) {
|
||||
m[attr] = m2[attr];
|
||||
}
|
||||
@ -83,7 +83,7 @@ export function merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key:
|
||||
|
||||
export function forEach<K, V>(
|
||||
map: {[key: string]: V}, callback: /*(V, K) => void*/ Function): void {
|
||||
for (var prop in map) {
|
||||
for (const prop in map) {
|
||||
if (map.hasOwnProperty(prop)) {
|
||||
callback(map[prop], prop);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export class Tree<T> {
|
||||
|
||||
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> {
|
||||
if (expected === c.value) return c;
|
||||
for (let cc of c.children) {
|
||||
for (const cc of c.children) {
|
||||
const r = findNode(expected, cc);
|
||||
if (r) return r;
|
||||
}
|
||||
@ -68,7 +68,7 @@ function findPath<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): Tre
|
||||
collected.push(c);
|
||||
if (expected === c.value) return collected;
|
||||
|
||||
for (let cc of c.children) {
|
||||
for (const cc of c.children) {
|
||||
const cloned = collected.slice(0);
|
||||
const r = findPath(expected, cc, cloned);
|
||||
if (r.length > 0) return r;
|
||||
|
Reference in New Issue
Block a user