Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- var count = 0;
- var totalCount = 0;
- var matrix = [];
- for (var i = 0; i < args.length - 1 ; i++) {
- var couple = args[i] + args[i + 1];
- for (var j = 0; j < args.length - 1; j++) {
- var testCouple = args[j] + args[j + 1];
- if (couple === testCouple) {
- count++;
- }
- }
- if (matrix.indexOf(couple + " " + count) === -1) {
- matrix.push(couple + " " + count);
- totalCount += count;
- }
- count = 0;
- }
- for (var i = 0; i < matrix.length; i++) {
- var couple = matrix[i].split(" ");
- console.log(couple[0] + " " + "->" + " " + parseInt(couple[1]) / totalCount * 100 + "%");
- }
- }
- console.log(solve(['3', '4', '2', '3', '4', '2', '1', '12', '2', '3', '4']));
Advertisement
Add Comment
Please, Sign In to add comment