Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions calculateFrequency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function calculateFrequency(string) {
let toReturn = {};
for (let i = 0; i < string.length; i++) {
if (string.charCodeAt(i) > 96 && string.charCodeAt(i) < 123) {
toReturn[string.charAt(i)] = 0;
}
}
for (let i = 0; i < string.length; i++) {
if (string.charCodeAt(i) > 96 && string.charCodeAt(i) < 123) {
toReturn[string.charAt(i)] = toReturn[string.charAt(i)] + 1;
}
}
return toReturn;
}

16 changes: 16 additions & 0 deletions flatten.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function flatten(unflatObject) {
var toReturn = {},
count = 0;
for (var i in unflatObject) {
if ((typeof unflatObject[i]) == 'object') {
var flatObject = flatten(unflatObject[i]);
for (var x in flatObject) {
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = unflatObject[i];
}
}
return toReturn;
}

Empty file removed readme.txt
Empty file.
25 changes: 25 additions & 0 deletions secondLargest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function secondLargest(array) {
let v = [];
v.length = 1000;
for (let i = 0; i < v.length; i++) {
v[i] = 0;
}
len = array.length;
for (let i = 0; i < array.length; i++) {
if (v[array[i]] == 1) {
len = len - 1;
} else {
v[array[i]] = 1;
}
}
let i = 0,
count = 0;
while (count < len - 1) {
if (v[i] == 1) {
count = count + 1;
}
i++;
}
return i - 1;
}

30 changes: 30 additions & 0 deletions unflatten.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function unflatten(flatObject) {
temp = {};
for (var key in flatObject) {
array = key.split('.');
var ret = function (obj, array, count) {
if (count < array.length - 1) {
if (typeof obj[array[count]] == 'object') {
obj[array[count]];
ret(obj[array[count]], array, count + 1);
}
else {
obj[array[count]] = {};
ret(obj[array[count]], array, count + 1);
}
}
else {
obj[array[count]] = flatObject[key];
}
return obj;
}
var extend = function (obj, src) {
for (var key in src) {
if (src.hasOwnProperty(key)) obj[key] = src[key];
}
return obj;
}
temp = extend(ret(temp, array, 0), temp);
}
return temp;
}