Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
layout: default
title: Basic Algorithm Scripting
parent: JavaScript Algorithms and Data Structures
has_children: true
nav_order: 5
---
# Basic Algorithm Scripting
An algorithm is a series of step-by-step instructions that describe how to do something.

To write an effective algorithm, it helps to break a problem down into smaller parts, and think carefully about how to solve each part with code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
layout: default
title: $$$
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: ##
---
# $$$
## Summary
-

## Final Code

{% highlight JavaScript %}

{% endhighlight %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
layout: default
title: Convert Celsius to Fahrenheit
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: 1
---
# Convert Celsius to Fahrenheit

## Final Code

{% highlight JavaScript %}
function convertToF(celsius) {
let fahrenheit = celsius*9/5+32;
return fahrenheit;
}

convertToF(30);
{% endhighlight %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
layout: default
title: Reverse a String
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: 2
---
# Reverse a String

## Final Code

{% highlight JavaScript %}
function reverseString(str) {
for (var reversedStr = "", i = str.length - 1; i >= 0; i--) {
reversedStr += str[i];
}
return reversedStr;
}

reverseString("hello");
{% endhighlight %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
layout: default
title: Factorialize a Number
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: 3
---
# Factorialize a Number

## Final Code

{% highlight JavaScript %}
function factorialize(num) {
for (var product = 1; num > 0; num--) {
product *= num;
}
return product;
}

factorialize(5);
{% endhighlight %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
layout: default
title: Find the Longest Word in a String
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: 4
---
# Find the Longest Word in a String

## Final Code

{% highlight JavaScript %}
function findLongestWordLength(str) {
let words = str.split(' ');
let maxLength = 0;

for (let i = 0; i < words.length; i++) {
if (words[i].length > maxLength) {
maxLength = words[i].length;
}
}

return maxLength;
}
{% endhighlight %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
layout: default
title: Return Largest Numbers in Arrays
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: 5
---
# Return Largest Numbers in Arrays

## Final Code

{% highlight JavaScript %}
function largestOfFour(arr) {
let results = [];
for (let i = 0; i < arr.length; i++) {
let largestNumber = arr[i][0];
for (let j = 1; j < arr[i].length; j++) {
if (arr[i][j] > largestNumber) {
largestNumber = arr[i][j];
}
}
results[i] = largestNumber;
}

return results;
}
{% endhighlight %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
layout: default
title: Confirm the Ending
parent: Basic Algorithm Scripting
grand_parent: JavaScript Algorithms and Data Structures
has_children: false
nav_order: 6
---
# Confirm the Ending

## Final Code

{% highlight JavaScript %}
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor

return str.slice(str.length - target.length) === target;
}

confirmEnding("He has to give me a new name", "name");
{% endhighlight %}