Skip to content

Commit 8c4b8a7

Browse files
committed
created
1 parent c6cde3e commit 8c4b8a7

File tree

362 files changed

+5796
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

362 files changed

+5796
-2
lines changed

Diff for: Basic Algorithm Scripting/boo-who.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function booWho(bool) {
2+
if(bool===true ||bool===false)
3+
return true
4+
else
5+
return false;
6+
}
7+
8+
booWho(null);

Diff for: Basic Algorithm Scripting/chunky-monkey.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function chunkArrayInGroups(arr, size) {
2+
let result=[];
3+
for(let i=0;i<arr.length;i=i+size)
4+
{
5+
result.push(arr.slice(i,(i+size)))
6+
}
7+
return result;
8+
}
9+
10+
chunkArrayInGroups(["a", "b", "c", "d"], 2);

Diff for: Basic Algorithm Scripting/confirm-the-ending.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function confirmEnding(str, target) {
2+
let targetlength=target.length;
3+
let startindex=str.length-targetlength;
4+
let result=str.substring(startindex);
5+
return result===target;
6+
}
7+
8+
confirmEnding("Bastian", "n");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function convertCtoF(celsius) {
2+
let fahrenheit=(celsius*(9/5))+32;
3+
return fahrenheit;
4+
}
5+
6+
convertCtoF(30);

Diff for: Basic Algorithm Scripting/factorialize-a-number.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function factorialize(num) {
2+
let f=1;
3+
for(let i=1;i<=num;i++)
4+
{
5+
f=f*i;
6+
}
7+
return f;
8+
}
9+
10+
factorialize(5);

Diff for: Basic Algorithm Scripting/falsy-bouncer.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function bouncer(arr) {
2+
let x = [];
3+
for (let i = 0; i < arr.length; i++) {
4+
if (arr[i] !== false && arr[i] !== null && arr[i] !== 0 && arr[i] !== undefined && !Number.isNaN(arr[i]) && arr[i] !== "") {
5+
x.push(arr[i]);
6+
}
7+
}
8+
return x;
9+
}
10+
11+
bouncer([7, "ate", "", false, 9]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function findLongestWordLength(str) {
2+
let words=str.split(' ');
3+
let max=0;
4+
for(let i=0;i<words.length;i++)
5+
{
6+
if(words[i].length>max)
7+
max=words[i].length;
8+
}
9+
return max;
10+
}
11+
12+
findLongestWordLength("The quick brown fox jumped over the lazy dog");

Diff for: Basic Algorithm Scripting/finders-keepers.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function findElement(arr, func) {
2+
let num = 0;
3+
for(let i=0;i<arr.length;i++)
4+
{
5+
if(arr[i]%2===0)
6+
{
7+
num=arr[i];
8+
break;
9+
}
10+
}
11+
if(num===0)
12+
{
13+
return undefined;
14+
}
15+
return num;
16+
}
17+
18+
findElement([1, 2, 3, 4], num => num % 2 === 0);

Diff for: Basic Algorithm Scripting/mutations.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function mutation(arr) {
2+
// Convert both strings to uppercase to make the comparison case-insensitive
3+
let x1 = arr[0].toUpperCase();
4+
let x2 = arr[1].toUpperCase();
5+
6+
// Loop through each character in the second string
7+
for (let i = 0; i < x2.length; i++) {
8+
// Check if the current character in the second string is not found in the first string
9+
if (x1.indexOf(x2[i]) < 0) {
10+
// If a character is not found, return false immediately
11+
return false;
12+
}
13+
}
14+
// If all characters in the second string are found in the first string, return true
15+
return true;
16+
}
17+
18+
// Test the function with ["hello", "hey"]
19+
mutation(["hello", "hey"]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function repeatStringNumTimes(str, num) {
2+
let r="";
3+
for(let i=0;i<num;i++)
4+
{
5+
r=r+str;
6+
}
7+
if(num<0)
8+
return "";
9+
else
10+
return r;
11+
}
12+
13+
repeatStringNumTimes("abc", 3);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function largestOfFour(arr) {
2+
let resultarr=[];
3+
for(let i=0;i<arr.length;i++)
4+
{
5+
let max=-9999999999;
6+
for(let j=0;j<arr[i].length;j++)
7+
{
8+
if(arr[i][j]>max)
9+
{
10+
max=arr[i][j];
11+
}
12+
}
13+
resultarr.push(max);
14+
}
15+
return resultarr;
16+
}
17+
18+
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Diff for: Basic Algorithm Scripting/reverse-a-string.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function reverseString(str) {
2+
let newstr="";
3+
for(let i=0;i<str.length;i++)
4+
{
5+
let ch=str.charAt(i);
6+
newstr=ch+newstr;
7+
}
8+
str=newstr;
9+
return str;
10+
}
11+
12+
reverseString("hello");

Diff for: Basic Algorithm Scripting/slice-and-splice.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function frankenSplice(arr1, arr2, n) {
2+
// Copy arr2 to avoid modifying the original array
3+
let newArr = arr2.slice();
4+
5+
// Loop through each element in arr1
6+
for (let i = 0; i < arr1.length; i++) {
7+
// Use splice to insert the current element of arr1 into newArr
8+
// The index at which to insert is calculated as n + i
9+
// 0 is the delete count (we're not deleting any elements)
10+
// arr1[i] is the element to insert
11+
newArr.splice(n + i, 0, arr1[i]);
12+
}
13+
14+
// Return the modified newArr with arr1 spliced in at index n
15+
return newArr;
16+
}
17+
18+
// Example usage: splice [1, 2, 3] into [4, 5, 6] at index 1
19+
frankenSplice([1, 2, 3], [4, 5, 6], 1);

Diff for: Basic Algorithm Scripting/title-case-a-sentence.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function titleCase(str) {
2+
let words = str.toLowerCase().split(' ');
3+
for (let i = 0; i < words.length; i++) {
4+
words[i] = words[i][0].toUpperCase() + words[i].substring(1);
5+
}
6+
return words.join(' ');
7+
}
8+
9+
titleCase("I'm a little tea pot");

Diff for: Basic Algorithm Scripting/truncate-a-string.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function truncateString(str, num) {
2+
let x=str.substring(0,num);
3+
x=x+"...";
4+
if(str.length>num)
5+
return x;
6+
else
7+
return str;
8+
}
9+
10+
truncateString("A-tisket a-tasket A green and yellow basket", 8);

Diff for: Basic Algorithm Scripting/where-do-i-belong.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function getIndexToIns(arr, num) {
2+
arr.sort((a,b)=>a-b);
3+
let x;
4+
for(let i=0;i<arr.length;i++)
5+
{
6+
if(arr[i]>=num)
7+
{
8+
x=i;
9+
break;
10+
}
11+
}
12+
if(x===undefined)
13+
x=arr.length;
14+
return x;
15+
}
16+
getIndexToIns([40, 60], 50);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let myArray = ["a", "b", "c", "d"];
2+
// Only change code below this line
3+
myArray[1]="a";
4+
// Only change code above this line
5+
console.log(myArray);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let foods = {
2+
apples: 25,
3+
oranges: 32,
4+
plums: 28,
5+
bananas: 13,
6+
grapes: 35,
7+
strawberries: 27
8+
};
9+
10+
function checkInventory(scannedItem) {
11+
// Only change code below this line
12+
return foods[scannedItem];
13+
// Only change code above this line
14+
}
15+
16+
console.log(checkInventory("apples"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function mixedNumbers(arr) {
2+
// Only change code below this line
3+
arr.push(7, 'VIII', 9);
4+
arr.unshift('I', 2, 'three');
5+
// Only change code above this line
6+
return arr;
7+
}
8+
9+
console.log(mixedNumbers(['IV', 5, 'six']));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function htmlColorNames(arr) {
2+
// Only change code below this line
3+
arr.splice(0,2,'DarkSalmon','BlanchedAlmond');
4+
// Only change code above this line
5+
return arr;
6+
}
7+
8+
console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurquoise', 'FireBrick']));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const foods = {
2+
apples: 25,
3+
oranges: 32,
4+
plums: 28
5+
};
6+
7+
// Only change code below this line
8+
foods["bananas"]=13;
9+
foods["grapes"]=35;
10+
foods["strawberries"]=27;
11+
// Only change code above this line
12+
13+
console.log(foods);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function quickCheck(arr, elem) {
2+
// Only change code below this line
3+
if(arr.indexOf(elem)>=0)
4+
return true;
5+
else
6+
return false;
7+
// Only change code above this line
8+
}
9+
10+
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
let users = {
2+
Alan: {
3+
age: 27,
4+
online: true
5+
},
6+
Jeff: {
7+
age: 32,
8+
online: true
9+
},
10+
Sarah: {
11+
age: 48,
12+
online: true
13+
},
14+
Ryan: {
15+
age: 19,
16+
online: true
17+
}
18+
};
19+
20+
function isEveryoneHere(userObj) {
21+
// Only change code below this line
22+
if(userObj.hasOwnProperty('Alan')&&userObj.hasOwnProperty('Jeff')&&userObj. hasOwnProperty('Sarah')&&userObj.hasOwnProperty('Ryan'))
23+
return true;
24+
else
25+
return false;
26+
// Only change code above this line
27+
}
28+
29+
console.log(isEveryoneHere(users));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function spreadOut() {
2+
let fragment = ['to', 'code'];
3+
let sentence=['learning',...fragment,'is', 'fun']; // Change this line
4+
return sentence;
5+
}
6+
7+
console.log(spreadOut());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function copyMachine(arr, num) {
2+
let newArr = [];
3+
while (num >= 1) {
4+
// Only change code below this line
5+
newArr.push([...arr]);
6+
// Only change code above this line
7+
num--;
8+
}
9+
return newArr;
10+
}
11+
12+
console.log(copyMachine([true, false, true], 2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function forecast(arr) {
2+
// Only change code below this line
3+
arr=arr.slice(2,4);
4+
return arr;
5+
}
6+
7+
// Only change code above this line
8+
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let myNestedArray = [
2+
// Only change code below this line
3+
['unshift', false, 1, 2, 3, 'complex', 'nested'],
4+
['loop', 'shift', 6, 7, 1000, 'method'],
5+
['concat', false, true, 'spread', 'array',["deep"]],
6+
['mutate', 1327.98, 'splice', 'slice', 'push',[["deeper"]]],
7+
['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth',[[["deepest"]]]]
8+
// Only change code above this line
9+
];

0 commit comments

Comments
 (0)