@hydroweaver/

how-to-lose-a-it-job-in-10-minutes-35pi

Nodejs

Solution for https://dev.to/albinotonnina/how-to-lose-a-it-job-in-10-minutes-35pi, athough very basic stupid code !

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var cities = ['Tokyo', 'ripas', 'London','donlon', 'Rome', 'Dnloon', 'Kyoto', 'Paris'];

function group(arr){
	var dt1 = new Date();
	var m1 = dt1.getTime();

	console.log(m1);

	var decomp = [];
	var result = [];
	var interim = [];
	var val = 0;
	var ascii = 0;
	for(var i =0;i<arr.length;i++){
		for(var j =0;j<arr[i].length;j++){
			var getLower = arr[i][j].toLowerCase();
			ascii += getLower.charCodeAt();
		}
		decomp.push(ascii);
		ascii = 0;
	}


	for(var i = 0; i <decomp.length;i++){
		if(interim.length===0){
			interim.push(decomp[i]);
		}
		else{
			if(interim.indexOf(decomp[i])===-1){
				interim.push(decomp[i]);
			}
		}
	}

	for(var i = 0;i<interim.length;i++){
		val = interim[i];
		var interim2 = [];
		for(var j = 0;j<decomp.length;j++){
			if(decomp[j]===val){
				interim2.push(arr[j]);
			}
		}
		result.push(interim2);
	}

	var dt2 = new Date();
	var m2 = dt2.getTime();

	console.log(m2);

	return result;
};

group(cities);

/* old version which only clubbed two different values

var cities = ['Tokyo', 'London','donlon', 'Rome', 'Dnloon', 'Kyoto', 'Paris']

function group(arr){
	var decomp = [];
	var result = [];
	var ascii = 0;
	var check = 0;
	for(var i =0;i<arr.length;i++){
		for(var j =0;j<arr[i].length;j++){
			var getLower = arr[i][j].toLowerCase();
			console.log(getLower,' ',getLower.charCodeAt());
			ascii += getLower.charCodeAt();
		}
		console.log('ASCII Total for %s is %d ', arr[i], ascii)
		console.log('\n');
		decomp.push(ascii);
		ascii = 0;
	}
	console.log(decomp);

	for(var i =0;i<decomp.length;i++){
		for(var j=0;j<decomp.length;j++){
			if(i != j && decomp[i] != '#' & decomp[j] != '#'){
				if(decomp[i]===decomp[j]){
					var check = 1;
					result.push([
						arr[i],
						arr[j]
					]);
					decomp[i] = '#';
					decomp[j] = '#';
				}
			}
		}
		if(check === 0 && decomp[i] != '#' & decomp[j] != '#'){
				result.push([arr[i]]);
			}
		check = 0;
	}
	return result;
};

*/
node v10.15.2 linux/amd64